Skip to content

Instantly share code, notes, and snippets.

@sehnryr
Created March 13, 2021 22:11
Show Gist options
  • Save sehnryr/a3dbdab5bdf1342bc3ace9ac01bc6e74 to your computer and use it in GitHub Desktop.
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`.
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