Using Powershell to see folder permissions


I’m very new at Powershell, so please excuse the potentially basic question.

I’m trying to see the security permissions/access for selected folders, and the sub folders within them, and export them as a .csv . I found the following code online (please ignore the specific paths included):

$FolderPath = dir -Directory -Path "C:\Temp" -Recurse -Force
$Report = @()
Foreach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    foreach ($Access in $acl.Access)
            $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
Group or
            $Report += New-Object -TypeName PSObject -Property $Properties
$Report | Export-Csv -path "C:\temp\FolderPermissions.csv" 

This seems to work well if I change the path in the first line, and the .csv output location for each folder.

However I was wondering if there was a way to speed this up? I have a .csv file of all the folder paths and corresponding output names. Eg. C:\example and ‘myexample’.

In an ideal world, it would go through each pair, look at all the folder permissions for the folders within the named folder path, then spit out a .csv with corresponding names in another folder. I imagine the way to do it is import the folder path/name .csv, create a variable then do a ‘for each’ type command, but I don’t know how to do it and integrate it into the above code.

Many thanks!

Welcome to the forum. :wave:t4:

If you found the code online I’d suggest to contact the author of this code and ask himor her for help in the first place.
Regardless of that the code is badly formatted and partly broken because of line breaks where they’re not allowed to be.

To get you started anyway you may start with reading the help for the most suitable cmdlets for this task. You can run the following commands to load their according help articles online or locally

Get-Help Import-Csv -Online
Get-Help Foreach-Object -Online
Get-Help about_foreach -ShowWindow

I would recommend that you look at the NTFSSecurity module on the PowerShell Gallery. It produces nice clean output. The command that you are looking for in that module is Get-NTFSAccess