In my previous post, I showed how to create a new ACL and apply it to a folder. Why apply it to the folder if the folder is already set correctly? I wrote the following function to compare the ACLs of a folder to a desired set of ACLs (either created by hand (lines 3-12) or copied from an existing folder (lines 12-15).
function JBMURPHY-PERMS-ArePermsCorrect {
Param([parameter(Mandatory = $true)]$Path,
[parameter(Mandatory = $true)]$CorrectACL,
[switch]$ShowCorrect)
$folderACLs=get-acl(get-item $Path)
if ((compare-object $($folderACLs.access) $($CorrectACL.access) -property FileSystemRights,IdentityReference,InheritanceFlags,PropagationFlags).count -gt 0) {
Write-host "$PATH is INCORRECT"
return $false
}
else {
if ($ShowCorrect.IsPresent){write-host "$PATH is correct"}
return $true
}
}
If the compare-object command returns nothing, then they are the same, if they are not the same then the items returned will be greater than 0, and the first part of the conditional will be used.

