locked
Powershell script for exporting permissions for multiple folder paths RRS feed

  • Question

  • I am relatively new to powershell so I would like a script to help exporting multiple folder permissions to a CSV file. So apologies if this has been asked before.

    I only need permissions at that folder level any file within that folder can be ignored 

    I know I can use Get-Acl "\\server\folder\folder" I Format-List this gives me an ideal view of what I am looking for. I tried Get-Acl "\\server\folder\folder" I Format-List  I export-csv C;\folder\folder\results.csv and also  Get-Acl "\\server\folder\folder" I Format-List  I export-csv C;\folder\folder\results.txt but the results were not as initially displayed when just running  Get-Acl "\\server\folder\folder" I Format-List. I obviously missing something.

    To make things more interesting I have a text file with over 2000 folder paths I need to check and return the results from.

    Is there a way of using this file as a lookup table and produce a single csv or txt file with the results.

    Thanks.
    • Moved by Bill_Stewart Friday, January 26, 2018 3:31 PM Unanswerable drive-by question
    Thursday, December 14, 2017 12:19 PM

All replies

  • You cannot export the output of any "format" commands.  Export-Csv only works on objects.


    \_(ツ)_/

    Thursday, December 14, 2017 12:46 PM
  • You cannot export the output of any "format" commands.  Export-Csv only works on objects.


    \_(ツ)_/

    Thanks, My understanding of powershell has now increased...

    But can you help with the script to do the job listed above?

    Thursday, December 14, 2017 2:23 PM
  • you could try something like this, just have a text file with the paths to each folder on a separate line

    $FolderNames = Get-Content C:\temp\Foldernames.txt
    ForEach($FolderName in $FolderNames){
    
        $Permissions = (Get-Acl $FolderName).access | select @{n='Identity';e={ ($_.IdentityReference.ToString().Split("\"))[1] }}, FileSystemRights 
            foreach($Permission in $Permissions)
        {
        
          $Report = New-Object PSObject
          $Report | Add-Member -MemberType NoteProperty -Name  Folder -Value $FolderName
          $Report | Add-Member -MemberType NoteProperty -Name UserName -Value $Permission.Identity
          $Report | Add-Member -MemberType NoteProperty -Nam Permission -Value $Permission.FileSystemRights
          $Report| export-csv c:\temp\FolderPermissions.csv -Append -NoTypeInformation -Force
    
          
        }
      
    }




    • Edited by simbrook2 Thursday, December 14, 2017 2:33 PM
    Thursday, December 14, 2017 2:28 PM