Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. Get-ChildItem C:UserDocs |
  2. ForEach-Object {
  3. if (!(Get-ADUser -Filter "sAMAccountName -eq '$($_.Name)'")) {
  4. "$($_.Name) does not exist and is being deleted."
  5. takeown /a /r /d Y /f $_.FullName
  6. $Acl = Get-Acl $_.FullName
  7. $Acl.AddAccessRule(
  8. (New-Object System.Security.AccessControl.FileSystemAccessRule(
  9. [System.Security.Principal.WindowsIdentity]::GetCurrent().Name,
  10. "FullControl",
  11. "ContainerInherit, ObjectInherit",
  12. "None",
  13. "Allow"
  14. ))
  15. )
  16. (Get-Item $_.FullName).SetAccessControl($Acl)
  17. Remove-Item -LiteralPath $_.FullName -Force -Recurse
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement