Guest User

Untitled

a guest
Sep 1st, 2022
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Path = "C:\Windows\System32\config\systemprofile\AppData\Local"
  2. #(gci $Path -r -force | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0}
  3. (gci $Path -r -force | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | remove-item
  4. Powershell ISE als Admin ausführen, reinkopieren. Das Skript löscht nur leere Ordner.
  5.  
  6. Alternativ:
  7. $FileList = Get-ChildItem C:\Windows\System32\config\systemprofile\AppData\Local\ -Include tw-* -Recurse -force
  8. foreach ($File in $FileList)
  9. {
  10. Write-Output $File.FullName
  11.     Try
  12.     {
  13.         #Remove-Item $File.FullName -Force -ErrorAction Stop
  14.         Remove-Item $File.FullName -Force -ErrorAction Stop -WhatIf
  15.         Write-Output "Deleted: $($File.Parent)\$($File.Name)"
  16.     }
  17.     Catch
  18.     {
  19.         Write-Output "Error deleting: $($File.Parent)\$($File.Name); Error Message: $($_.Exception.Message)"
  20.     }
  21. }
  22. Zum wirklichen löschen, bitte # bei -Whatif hinzufügen und # bei dem darüberliegenden Befehl entfernen.
  23. # entspricht REM in Batch Dateien.
Tags: powershell
Advertisement
Add Comment
Please, Sign In to add comment