Set folder inheritance

 

folder

In the last blogg I wrote in how to find differens in source and target folder inheritance. Here is a scritpt to enable the inheritance on multiple folders listed in an csv-file. The acl.SetAccessruleProtection line only sets the flag and the you have to commit with set-acl, hopefully this will change in future versions.

Had to use google on this one because the strange way to implement this. http://richardspowershellblog.wordpress.com/2008/02/06/file-system-allow-inheritable-permissions-from-parent-to-propagate/

#----------------
---------------------------------------------
#NAME: Set folder inheritance.ps1
#AUTHOR: Viktor Lindström
#
#COMMENTS: Set inheritance behavior on folders 
#-------------------------------------------------------------
$Import = import-csv "c:\test\folders.csv


foreach ($path in $import)
{
$acl= Get-Acl -Path $path 
$acl.AreAccessRulesProtected
$isProtected = $false
$preserveInheritance = $true
$acl.SetAccessRuleProtection($isProtected, $preserveInheritance)
Set-Acl -Path $path -AclObject $acl 
}

 

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:

Job;Source;Target
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"