Hi. I need to get an ACL of all folders.
I have a powershell command:
(Get-ACL -Path “Folder1”). Access | Format-Table
This command works fine. However, changing the “folder1” field is a pain. Can I combine this command with “dir”? so as to have a list of all folders and not just 1?
Of course. That’s what scripting has been invented for.
BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
I saved it as a script. However, when I try to run I have:
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\uprawnienia\1.ps1:1 char:39
+ $FolderPath = Get-ChildItem -Directory <<<< -Path "e:\MY_FOLDER" -Recurse -Force
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-Acl : Cannot validate argument on parameter 'Path'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\uprawnienia\1.ps1:4 char:25
+ $Acl = Get-Acl -Path <<<< $Folder.FullName
+ CategoryInfo : InvalidData: (:) [Get-Acl], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAclCommand
Unable to find type [ordered]: make sure that the assembly containing this type is loaded.
At C:\uprawnienia\1.ps1:6 char:24
+ $Properties = [ordered] <<<< @{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
+ CategoryInfo : InvalidOperation: (ordered:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
New-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\uprawnienia\1.ps1:7 char:51
+ $Output += New-Object -TypeName PSObject -Property <<<< $Properties
+ CategoryInfo : InvalidData: (:) [New-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewObjectCommand
Out-GridView : To use the Out-GridView cmdlet, install the Windows PowerShell Integrated Scripting Environment feature from Server Manager. (Nie można załadować pliku lub zestawu 'Microsoft.PowerShell.GraphicalHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' lub jednej z jeg
o zależności. Nie można odnaleźć określonego pliku.)
At C:\uprawnienia\1.ps1:10 char:23
+ $Output | Out-GridView <<<<
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...1bf3856ad364e35:AssemblyName) [Out-GridView], NotSupportedException
+ FullyQualifiedErrorId : ErrorLoadingAssembly,Microsoft.PowerShell.Commands.OutGridViewCommand
I’m a step ahead but still not what I want to get.
I need ACL access list for folders (no subfolders)
The problem is the -DIRECORY parameter
After removing this parameter, something starts to happen but I still do not have acl list, i.e. what user has access to the folder. I have an error:
Get-ChildItem : No acces to path 'c:\my_folder1'.
At C:\uprawnienia\2.ps1:2 char:18
+ Get-ChildItem <<<< -Path 'c:\my_folder\1' -Recurse -Force
+ CategoryInfo : PermissionDenied: (c:\my_folder\1\Data:String) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Why do you use the parameter -Recurse then? Remove it!
That’s why I asked what PowerShell version you use. This parameter exists since version 3.0. If you’re using version 2.0 you have to filter for only folders with a Where-Object.
BTW: It may be a typo here in your post but the parameter name is -Directory - not -DIRECORY
The error message is pretty obvious. Don’t you think?
thank you.
You’re helping me a lot: slight_smile: I’m getting closer… you’re right, I have an old version of POWERSHEL and I can’t update it because it’s quite an important machine. I corrected the script
All Windows systems comming with a PowerShell version prior to version 3.0 are not supported anymore for years. How important can a system be when it’s in an unsupported state?
First … I’d recommend to use your favorite search engine to look for answers BEFORE you ask in a forum!!
Second … do a big step back and start with learning the very basics of PowerShell first. That will save you from a lot of wasted time and frustrations.
Then … always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them