Created
February 21, 2020 13:07
-
-
Save csharpforevermore/afb97a8a85fda94680f920735c964e73 to your computer and use it in GitHub Desktop.
Powershell - set all rights to administrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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