Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Created February 1, 2019 14:46
Show Gist options
  • Save mbrownnycnyc/41a315f2da2e5ef90224276223ea0ba0 to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/41a315f2da2e5ef90224276223ea0ba0 to your computer and use it in GitHub Desktop.
get-acl/set-acl example
$userfqdn = "matt-surface\scanner"
$targetfolder = "C:\Users\Matt\Desktop\hassio"
$acl = get-acl $targetfolder
$acl.setaccessruleprotection($false, $false)
# FileSystemRights enum: https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.filesystemrights?view=netframework-4.7.2
# InheritanceFlags enum: https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.inheritanceflags?view=netframework-4.7.2
$ruleReadOnly = New-Object System.Security.AccessControl.FileSystemAccessRule($userfqdn,"ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow")
$ruleModify = New-Object System.Security.AccessControl.FileSystemAccessRule($userfqdn,"Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$ruleFullAccess = New-Object System.Security.AccessControl.FileSystemAccessRule($userfqdn,"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.addaccessrule($ruleReadOnly)
set-acl $targetfolder $acl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment