Created
October 30, 2024 21:58
-
-
Save sean-m/a3970b5eb57c19cffd96906fde786741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Takes and ACL and SID, returns an ACL with the correct entry for read-only permissions added. | |
function Add-ReadAce { | |
[OutputType([System.Security.AccessControl.FileSystemSecurity])] | |
param( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$false)] | |
[System.Security.Principal.IdentityReference]$SID, | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] | |
[System.Security.AccessControl.FileSystemSecurity]$ACL | |
) | |
# Rule applies to parent container, does not propagate | |
$aclRights = [System.Security.AccessControl.FileSystemRights]"Traverse, ExecuteFile, ListDirectory, ReadData, ReadAttributes, ReadExtendedAttributes, ReadPermissions" | |
$objectInherit = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit" | |
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None | |
$objType =[System.Security.AccessControl.AccessControlType]::Allow | |
$readACE = New-Object System.Security.AccessControl.FileSystemAccessRule ` | |
($SID, $aclRights, $objectInherit, $PropagationFlag, $objType) | |
$ACL.AddAccessRule($readACE) | |
return $ACL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment