Today I’ll be going over how to use Powershell to Get permissions on folders and subfolders, as well as NTFS permission report in an output file.
The PowerShell Get-ACL available in the Microsoft.PowerShell.Security module allows you to get permissions on folders (directories) and subfolders. Windows Operating Systems store info related to files, folders (directories), and subfolders permission in the Access Control List (ACL).
Lucky for us, PowerShell provides the Get-ACL cmdlet that provides the access control list for the given resource. The ACL contains the Users & Users group permissions to access the resource.
To view and parse the permissions on folder, use get-acl cmdlet
Powershell for extracting Permissions on Current Working Folder or Directory
To view the NTFS permissions report on current working folder or directory in PowerShell, we’ll be using Get-ACL cmdlet without no parameters. It will return the access control list for directory/folder.
PS C:\temp\>Get-ACL
In the example directly Above, Get-ACL finds the permissions on current working directory, here in C:\temp.
Output of the Get-Acl finds the permissions on folder as shown below:
Extract the NTFS permissions Report on Folder in Format-table
To extract and parse the output of PowerShell get-acl cmdlet on folder permissions in a Format-Table, use below command
PS C:\Temp> Get-Acl | Format-Table -Wrap
In the command Above, we get the NTFS permission report on folders and outputs results to Format-Table. Output of the above command as below
Extract Permission on Folders and Subfolders Recursively
We’ll be using the command below to extract permission on folders and subfolders using Get-ACL powershell command.
PS C:\PowerShell\>Get-ChildItem -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List
In the PowerShell code example above, to get permissions on folders and subfolders recursively, Get-ACL cannot show all folders and subfolders permission – Thus we’ll need to utilize the PowerShell Get-ChildItem cmdlet with -Recurse parameter.
Output of the the command pass through where-object{$_.PslsContainer} filter to select only folder. PsIsContainer get directory if its property in file system object set to true.
We can then use the Get-ACL cmdlet to extract the permissions on folders and subfolders recursively.
The Output of the command above will list permissions on the folder as given below
If you want to extract and get the folder permissions into a text file, then we’ll use the command shown below:
PS C:\computing> Get-ChildItem -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List | Out-File c:\Results.txt
The above command will extract the permissions the top-level folder and subfolders/directories in the “C:\computing” folder and get its permissions using the Get-ACL command and then out the results to a c:\Results.txt
Now that we’ve gone over the methods of extracting or getting the NTFS permissions and reporting them into a file, you’ll now have no issues with using Powershell to Get Permissions on Folder and Subfolders (or directories).