Skip to content

Instantly share code, notes, and snippets.

@Krelix
Created June 30, 2014 09:32
Show Gist options
  • Save Krelix/dfaf0710c3abe76a2c4c to your computer and use it in GitHub Desktop.
Save Krelix/dfaf0710c3abe76a2c4c to your computer and use it in GitHub Desktop.
PowerShell - Change permissions and owner of all the files and directories in the current folder.
# Don't forget to ser $usernameFull to the name off account in this format : DOMAIN\username
$rule = new-object System.Security.AccessControl.FileSystemAccessRule($usernameFull, 'FullControl', 'Allow');
$owner = new-object System.Security.Principal.NTAccount($usernameFull)
foreach($file in $(Get-ChildItem ./ -recurse)){
$acl=get-acl $file.FullName
$acl.SetAccessRule($rule)
$acl.SetOwner($owner)
set-acl $file.FullName $acl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment