Home » PowerShell » Get Permissions on folders and subfolders using PowerShell

Get Permissions on folders and subfolders using PowerShell

PowerShell Get-ACL cmdlet is available in Microsoft.PowerShell.Security module gets permissions on folders and subfolders. Windows OS stores information related to files, folders, and subfolders permission in Access Control List (ACL).

PowerShell provides a Get-ACL cmdlet that gets the access control list for the resource. The Access control list contains the user’s and users group permission to access the resource.

To get permissions on the folder, use the Get-ACL cmdlet

Get permissions on folder
Get permissions on folder

In this article, we will discuss how to get permissions on folders and subfolders and NTFS permission reports as output file.

Get permissions on the Current Working Directory

To get NTFS permissions report on the current working directory in PowerShell, use the Get-ACL cmdlet without any parameters. It returns an access control list for the directory.

PS C:\Temp\>Get-ACL

In the above example, the Get-ACL gets permissions on the current working directory, here in C:\Temp.

The output of the Get-Acl gets permission on the folder as below

PowerShell Get-ACL permissions on Current folder
PowerShell Get-ACL permissions on the folder

Cool Tip: How to Get Current Directory in PowerShell!

Get NTFS Permissions Report on Folder in Format-Table

To get the output of the PowerShell Get-Acl cmdlet on folder permissions in format-table, use the below command

PS C:\Temp> Get-Acl | Format-Table -Wrap

In the above command, it gets the NTFS permission report on folders and outputs results to Format-Table. The output of the above command as below

powershell get acl on folder
Get-ACL folders permission in Format-table

Do you know: How to use the equivalent of the cat command in Windows !

Get permission on Folders and Subfolders Recursively

Use the below command to get permission on folders and subfolders using Get-ACL

PS C:\PowerShell\>Get-ChildItem -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List

In the above PowerShell example, to get permissions on folders and subfolders recursively,

Get-ACL can’t return all folders and subfolders permission hence we need to use PowerShell Get-ChildItem cmdlet with -Recurse parameter.

The output of the command passes through where-object{$_.PslsContainer} filter to select only a folder. PsIsContainer gets a directory if its property in the file system object is set to true.

Later, using the Get-ACL cmdlet gets permissions on folders and subfolders recursively.

The output of the above command list permissions on the folder as given below

Get-ACL - Get permissions on folders and Subfolders
Get-ACL – Get permissions on folder and Subfolders

In case if you want to output folder permissions to a txt file, use the below command

PS C:\Temp> Get-ChildItem -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List | Out-File D:\folder-permission.txt

Above command, it gets the permission for folder and subfolders available in the C:\Temp folder and gets permissions for that resource using Get-ACL and outputs results to D:\folder-permission.txt file.

Cool Tip: How to set permission on files recursively using Set-Acl in PowerShell

Conclusion

In the above blog post, I have shown you how to get NFTS permission report using PowerShell for folders and subfolders.

I hope you found the above article on how to get permissions on folders and subfolders informative and educational.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.