I have our system builder’s system configuration scripts, and I recall a note about the Get-Acl command that doesn’t work on specific paths.
# NOTE: This method does not work well?
The types of paths on which we set the permissions were empty folders created by the administrator user, which were subsequently written to the disk image. This is the PowerShell command that we used instead.
$acl = (Get-Item $path).GetAccessControl("Access")
Oh, and it becomes real obscure when you have an ACL object. I don't know if this is the best way, but this is a snippet from the same script that I mentioned above.
$acl = (Get-Item $path).GetAccessControl("Access") # Setup the access rule. $allInherit = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit", "ObjectInherit" $allPropagation = [System.Security.AccessControl.PropagationFlags]"None" $AR = New-Object System.Security.AccessControl.FileSystemAccessRule $user, $permissions, $allInherit, $allPropagation, "Allow" # Check if Access already exists. if ($acl.Access | Where { $_.IdentityReference -eq $User}) { $accessModification = New-Object System.Security.AccessControl.AccessControlModification $accessModification.value__ = 2 $modification = $false $acl.ModifyAccessRule($accessModification, $AR, [ref]$modification) | Out-Null } else { $acl.AddAccessRule($AR) } Set-Acl -AclObject $acl -Path $Path
source share