Created
March 13, 2021 22:11
-
-
Save sehnryr/a3dbdab5bdf1342bc3ace9ac01bc6e74 to your computer and use it in GitHub Desktop.
PowerShell script that changes the permissions of files of a directory, granting `FullAccess` to the `BUILTIN\Administrators`.
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
if ($Args) | |
{ | |
$dir = $Args[0] -Join " " | |
$input = Read-Host -Prompt "Are you sure you want to execute the fixing on ``$($dir)`` ? [y:N]" | |
if ($input -like "y") | |
{ | |
$files = Get-Childitem $Args[0] -recurse | where {! $_.PSIsContainer} | |
foreach ($file in $files) | |
{ | |
$acl = Get-Acl $file.fullName | |
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators","FullControl","Allow") | |
$acl.SetAccessRule($AccessRule) | |
$acl | Set-Acl $file.fullName | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment