ZeroSharp

Robert Anderson's ones and zeros

How to Recursively Change File Ownership

| Comments

I recently ran into some file ownership trouble after cloning a bitbucket repository.

The following script saved my bacon.

FixOwnership.ps1
1
2
3
4
5
6
7
8
9
# This script recursively fixes the ownership on the files in the 
# current and subdirectories.

$acct1 = New-Object System.Security.Principal.NTAccount('Administrators')
$profilefolder = Get-Item .
$acl1 = $profilefolder.GetAccessControl()
$acl1.SetOwner($acct1)
dir -r . | set-acl -aclobject $acl1
pause

Comments