Acces all foder ACL

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?

Marcin,
Welcome to the forum. :wave:t4:

Of course. That’s what scripting has been invented for. :+1:t4: :wink:

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.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

I keep trying to start up and nothing comes out. I tried to use this:

$FolderPath = Get-ChildItem -Directory -Path "e:\MY_FOLDER" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Output += New-Object -TypeName PSObject -Property $Properties            
}
}
$Output | Out-GridView

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

Siemanko,
Try to remove -Directory from $folderpath

$FolderPath = Get-ChildItem -Path "e:\MY_FOLDER" -Recurse -Force

What PowerShell version do you use?

Something like this should work.

$FolderList = 
    Get-ChildItem -Path 'e:\MY_FOLDER' -Recurse -Force -Directory

$Output = 
    ForEach ($Folder in $FolderList) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
            [PSCustomObject]@{
                'Folder Name' = $Folder.FullName
                'Group/User'  = $Access.IdentityReference
                'Permissions' = $Access.FileSystemRights
                'Inherited'   = $Access.IsInherited
            }
        }
    }

$Output |
    Out-GridView

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? :man_shrugging:t4: Remove it! :point_up_2:t4:

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 :wink:

The error message is pretty obvious. Don’t you think? :wink:

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

$FolderList = 
    Get-ChildItem -Path 'e:\MY_FOLDER' -Force -Directory

$Output = 
    ForEach ($Folder in $FolderList) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
            [PSCustomObject]@{
                'Folder Name' = $Folder.FullName
                'Group/User'  = $Access.IdentityReference
                'Permissions' = $Access.FileSystemRights
                'Inherited'   = $Access.IsInherited
            }
        }
    }

$Output |
    Out-GridView

this show error:

Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\uprawnienia\2.ps1:2 char:57
+     Get-ChildItem -Path 'e:\MY_FOLDER' -Force -Directory <<<<
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

i remove this

$FolderList = 
    Get-ChildItem -Path 'e:\MY_FOLDER' -Force

$Output = 
    ForEach ($Folder in $FolderList) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
            [PSCustomObject]@{
                'Folder Name' = $Folder.FullName
                'Group/User'  = $Access.IdentityReference
                'Permissions' = $Access.FileSystemRights
                'Inherited'   = $Access.IsInherited
            }
        }
    }

$Output |
    Out-GridView

and still error

Get-Acl : An attempt was made to perform an unauthorized operation.
At C:\uprawnienia\2.ps1:6 char:23
+         $Acl = Get-Acl <<<<  -Path $Folder.FullName
    + CategoryInfo          : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand

I don’t get it a bit.
Recommendation:

(Get-ACL -Path “c:\my_folder”).Access | Format-Table

works properly…

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? :thinking:

You can use

| Where-Object { $_.PSIsContainer }

to filter for folders only.

Everything works fine now. THX, THX, THX, :slight_smile:

last request
Can you tell me what I can change to get the result in the TXT file no c: \ aaa.txt and not in the table?

$Output |
    Out-GridView

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

1 Like