Skip to content

Instantly share code, notes, and snippets.

@dizys
Created September 16, 2021 18:17
Show Gist options
  • Save dizys/dbba00894bb70b536ac594a6bf91559c to your computer and use it in GitHub Desktop.
Save dizys/dbba00894bb70b536ac594a6bf91559c to your computer and use it in GitHub Desktop.
Lost edit permissions of files (Access Denied, I know) after reinstalling your Windows? Copy this file to the folder where you want all the subfolders and files to be in your control again. Run it in PowerShell with administrator privileges, then delete or edit them again!
foreach ($file in Get-ChildItem . -Recurse)
{
$path = Get-Item -LiteralPath $file.FullName
$acl = $path.GetAccessControl()
$permission = "Everyone","FullControl","Allow"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($rule)
$path.SetAccessControl($acl)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment