Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created February 21, 2020 13:07
Show Gist options
  • Save csharpforevermore/afb97a8a85fda94680f920735c964e73 to your computer and use it in GitHub Desktop.
Save csharpforevermore/afb97a8a85fda94680f920735c964e73 to your computer and use it in GitHub Desktop.
Powershell - set all rights to administrator
# Define the owner account/group
$Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList 'BUILTIN\Administrators';
# Get a list of folders and files
$ItemList = Get-ChildItem -Path D:\Applications\Leafletdrop.Q4CmsChange\Media\Default -Recurse;
# Iterate over files/folders
foreach ($Item in $ItemList) {
$Acl = $null; # Reset the $Acl variable to $null
$Acl = Get-Acl -Path $Item.FullName; # Get the ACL from the item
Write-Output "File: " + $Acl + "(" + $Account + ")";
$Acl.SetOwner($Account); # Update the in-memory ACL
Set-Acl -Path $Item.FullName -AclObject $Acl; # Set the updated ACL on the target item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment