Powershell: How to get folder permissions

We know that Windows stores the information related to File permissions for an object in Access Control Lists (ACLs).

Type Get-Help *ACL | Format-Table -Autosize - Wrap to find the related cmdlets available to us.

http://www.enterprisedaddy.com/wp-content/uploads/2015/05/Capture11.png

Now we are presented with two cmdlets Get-ACL and Set-ACL along with their descriptions.

It is pretty clear now that we will be using Get-ACL to retrieve the required information.

Let us say that we want to find the permissions for the sub folders in Windows Folder on C drive.

To Find the subfolders, we will be using Get-ChildItem, which is similar to dir from Command Prompt or ls if you are a Linux guy.

Get-ChildItem .\Windows | where-object {($_.PsIsContainer)} | Get-ACL | Format-List

Note that we have used PsIsContainer as a filter. The where-object {($_.PsIsContainer)} will make sure only the directory is shown. Without this filter, all the files and folders will show up on your result.

http://www.enterprisedaddy.com/wp-content/uploads/2015/05/Capture2.png

If you would like to research more on the Get-ACL properties, here is an handy one-liner.

Get-Acl C:\Windows | Get-Member -MemberType *Property

MemberType *Property filters out methods, and shows just the various properties.

If we need to find the permissions on each and every sub folder then we will need to -Recurse parameter along with Get-ChildItem. Therefore, the cmdlet will look like.

Get-ChildItem .\Windows -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List

And we have to output the results to a text file, the cmdlet will be as below.

Get-ChildItem .\Windows -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List | Out-File C:\Permissions.txt