Using Powershell to see folder permissions

Hi,

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
User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
            $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!

klo01,
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