Guest User

Delete temp files

a guest
Mar 2nd, 2014
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #PowerShell Script to clean out temporary folders
  2.  
  3. #Load Active Directory PowerShell Module
  4. Import-Module activedirectory
  5.  
  6. #Variable array for folders to clean, others can be added as needed
  7. #$tempfolders = @("C:\Windows\Temp\*", "C:\Windows\Prefetch\*", "C:\Documents and Settings\*\Local Settings\temp\*", "C:\Users\*\Appdata\Local\Temp\*")
  8.  
  9. #AD Path to search for computers to clean
  10. $searchbase = "OU=Delete Files,OU=Computers,OU=Arbitrary,DC=company,DC=com"
  11.  
  12. #Get the list of computers to clean
  13. $query = Get-ADComputer -Filter * -SearchBase $searchbase | Sort DNSHostName
  14. $computers = $query.DNSHostName
  15.  
  16. #Error Handling Preference
  17. #$ErrorActionPreference = "SilentlyContinue"
  18.  
  19. #Operation to clear out temp files in specificed folders
  20.  
  21. #WinRM method, requires winrm quickconfig -q to be run on host machines first
  22. #invoke-command -computername $computers {remove-item $env:windir\temp\* -force -recurse}
  23.  
  24. #foreach loop method, can't get it to work
  25. foreach ($computer in $computers) {
  26. Remove-Item $env:windir\temp\* -force -recurse
  27. }
Advertisement
Add Comment
Please, Sign In to add comment