PowerShell: Change File Owner/ACL

By Xah Lee. Date: . Last updated: .

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

PowerShell

Practical How-To

list files

list dirs

on dir

on file

Windows config

zip tar

misc


PowerShell in Depth

Programing PowerShell

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples