PowerShell: Change File Owner/ACL
Files on unix/linux have owner/group/perm system. [Linux: File Permission System] Windows has something similar, called Access Control Lists (ACL).
To set a file's permission on Windows, first find a file whose ACL is the one you want, get its ACL using get-acl
, then copy it to the files you want to set to, using set-acl
.
Change a single file ACL
# change a single file ACL $acl = Get-Acl "~/t1.txt" $target = "~/t2.txt" Set-Acl $target -AclObject $acl
change all file ACL in a dir
# change all file ACL in a dir $acl = Get-Acl "~/Documents/x1" dir "~/web/" -Recurse -file | Set-Acl -AclObject $acl
change all dir ACL in a dir
# change all dir ACL in a dir $acl = Get-Acl "~/Documents/xx" dir "~/web/" -Recurse -directory | Set-Acl -AclObject $acl