FileSystemAclExtensions::GetAccessControl does not work until using Get-Acl once
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I have a script to create a report on filesystem permissions. For performance reasons I use [System.IO.FileSystemAclExtensions]::GetAccessControl()
instead of Get-Acl
.
This is working fine in 7,1.3 but does not work in 7.3.1 or 7.4.0-preview.1
Steps to reproduce:
[System.IO.FileSystemAclExtensions]::GetAccessControl( [System.IO.DirectoryInfo]::new( "c:\windows"))
It will provide the expected output after using Get-Acl
once, regardless of the path (e.g. Get-Acl HKCU:
).
Expected behavior
Path Owner Access
---- ----- ------
NT SERVICE\TrustedInstaller CREATOR OWNER Allow 268435456…
Actual behavior
Path Owner Access
---- ----- ------
Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
Issue Analytics
- State:
- Created 8 months ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Removing all ACL on folder with powershell
I'm currently working on a script with powershell 2.0 to clean folder NTFS ACL. I want to delete every acl except the administrator...
Read more >Get-Acl (Microsoft.PowerShell.Security)
This cmdlet is only available on the Windows platform. The Get-Acl cmdlet gets objects that represent the security descriptor of a file or...
Read more >An introduction to Linux Access Control Lists (ACLs)
They let us "tack on" access for other users or groups. We can view the current ACL using the getfacl command: [root]# getfacl...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MartinGC94 Using .net instead of a cmdlet may be harder, but in some cases the decrease of the script runtime is significant (see above: one minute compared to nearly half an hour. And this was just a small directory. The script is intended to run on much larger volumes).
@mklement0 I already added the import-module as Martin suggested and it solved my problem. I do not see this as a big deal. My problem was to identify what was missing.
Many thanks to all of you for your effort to explain and to provide helpful code (already saved for future use). I appreciate that very much.
ETS is a standard feature in PowerShell and I’m sure there’s some help topic that explains all the details. I’m not aware of any way to know where type data was loaded from but generally speaking, modules only modify type data for types they use.
As for startup time, I don’t know but every little bit helps. IMO PS is way too slow to start up.
As for using .NET, it may be faster but as you can see here you lose some of the benefits that PowerShell provides for you. The DirectorySecurity class doesn’t contain the properties that are missing in your screenshot: https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.directorysecurity so if you want to use .NET directly then be prepared to work a little harder.