Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################
- #Author = Bered
- #Created 19/01/2021
- #Name = Remove Unknown SIDs
- #Purpose - Find and remove and unknown SIDs (S-1-5-*) from a specific folder and subfolder.
- ######################################
- $Folders = Get-ChildItem '#>FILE PATH HERE<#' -Recurse
- foreach($Folder in $folders)
- {
- $Path = $folder.FullName
- $ACLSearch = Get-Acl -Path $Path
- foreach($ACL in $ACLSearch)
- {
- IF ( $ACL.Access.IsInherited -eq $false -and $ACL.Access.IdentityReference -like "S-1-5-*")
- {
- Write-Host $Path
- $Rule = $ACL.Access | ?{ $_.IsInherited -eq $false -and $_.IdentityReference -like "S-1-5-*"}
- Foreach ($SubRule in $Rule)
- {
- $acl.RemoveAccessRule($Subrule) | Out-Null
- Set-Acl -Path $Path -AclObject $ACL | Out-Null
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement