Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Get-ChildItem C:UserDocs |
- ForEach-Object {
- if (!(Get-ADUser -Filter "sAMAccountName -eq '$($_.Name)'")) {
- "$($_.Name) does not exist and is being deleted."
- takeown /a /r /d Y /f $_.FullName
- $Acl = Get-Acl $_.FullName
- $Acl.AddAccessRule(
- (New-Object System.Security.AccessControl.FileSystemAccessRule(
- [System.Security.Principal.WindowsIdentity]::GetCurrent().Name,
- "FullControl",
- "ContainerInherit, ObjectInherit",
- "None",
- "Allow"
- ))
- )
- (Get-Item $_.FullName).SetAccessControl($Acl)
- Remove-Item -LiteralPath $_.FullName -Force -Recurse
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement