Export folder permission using PowerShell

Recently we where moving folder and shares from one server to another. We need to confirm that the folder and permissions were the same on both the old and new share.

To do this I used PowerShell to export the pre and post move permissions and compare the results.

The two commands to get most of the information will be Get-ChildItem and Get-Acl.  The only part of the scripts that will need to be changed is the the export file name to give it a custom name.

Below is the link to full script I will be using.

https://github.com/TheSleepyAdmin/Scripts/tree/master/General/Folder%20Permission

To run the script there will be two mandatory parameters and the command should look like the below. (If you want to look up all subfolders also then just change line 14 and add -Recurse to Get-ChildItem command)

.\Get-FolderPermissions.ps1 -FolderPath \\lab-host01\sources -ExportPath D:\Scripts\Folder_Permissions\Export

I ran the script and changed the exported csv name to pre and post to be used to compare.
Per1
Below is what the export should look like.
Per2
Per3
Once the pre and post export are done we can use compare-object to find any differences.
Just need to update the import-csv paths, I was moving to a share that would have the same FQDN so if that is not the case you can removed the FolderPath from the compare-Object property otherwise all result will not match.
Below is the link to the script I used.
Per4Per5
Below is the export results showing the difference between the pre and post move Per6

4 thoughts on “Export folder permission using PowerShell

  1. Thankyou for a great script, saved me and others a lot of time!

    One question: Can we get this script to show subfolders also? it currently displays the folders under ‘Sources’ but not the subfolders of those folders 🙂 i hope that makes sense

    Thanks again

    Like

  2. Hi PB1882

    yep you can just add -Recurse to the Get-ChildItem

    so should just need to update this line from
    $Folders = Get-ChildItem -Path $Search | Select-Object Name,FullName,LastWriteTime,Length

    to this to get only folders and sub folders with no files.
    $Folders = Get-ChildItem -Path $Search -Recurse -Directory | Select-Object Name,FullName,LastWriteTime,Length

    Like

Leave a Reply to TheSleepyAdmin Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s