PowerShell: Change File Owner Perm (ACL)

By Xah Lee. Date: . Last updated: .

What is Access Control Lists (ACL)

Access Control Lists (ACL) is a file permission system on Microsoft Windows.

Change ACL for a single file

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.

$xacl = Get-Acl "~/t1.txt"
$target = "~/t2.txt"
Set-Acl $target -AclObject $xacl

Change ACL for all files in a dir

$xacl = Get-Acl "~/Documents/x.txt"
dir "~/web/" -Recurse -file | Set-Acl -AclObject $xacl

Change ACL for all dir in a dir

$xacl = Get-Acl "~/Documents/x.txt"
dir "~/web/" -Recurse -directory | Set-Acl -AclObject $xacl

PowerShell. File Properties, Attributes, Permission