Compare folder inheritance


inheritanceIn the middle of file server-migration where we migrated hundreds of folders in to a new folder structure on another server we had to compare the folder inheritance since it on the old sever where randomized. We made this script that uses an import from an csv file we used to handle the copy jobs source and target. The csv looked like this:

BUF01;N:\Groups\XX\BUF ADMINISTRATION;\\srv-fil05\Gemensam$\XX\Administration och nämnd
BUF02;N:\Groups\XX\EKONOMI;\\srv-fil05\Gemensam$\XX\Administration och nämnd

The script results in a file that displays all source paths that doesn´t compiles with the targets inheritance.

#NAME: Compare_inheritance.ps1
#AUTHOR: Viktor Lindström and Stefan Lozancic
#COMMENTS: Compare if folder inheritance is enabled or disabled 

$import = Import-Csv "C:\test\test.csv" -Delimiter ";" -Encoding UTF7
$folders = @()

foreach ($row in $import)

{$source = Get-Item $row.Source | get-acl | select pspath,AreAccessRulesProtected
$target = Get-Item $row.Target | get-acl | select pspath,AreAccessRulesProtected

if ($source.AreAccessRulesProtected -ne $target.AreAccessRulesProtected)
{$folders+= $row.Target
$folders | Out-File -FilePath "c:\test\folders.txt"