33 How to delete temp files from the various Windows location?

In the below PowerShell script:-

  1. Name and save the script as “Set-DeleteTemp.PS1”.
  2. Run the script from the PowerShell console.
  3. The output will be displayed within the PowerShell console.
In case of any hurdle, please Contact Us

Set-ExecutionPolicy Bypass -scope Process -Force
$tempfolders = @(“C:\Windows\Temp\*”, “C:\Windows\Prefetch\*”, “C:\Documents and Settings\*\Local Settings\temp\*”, “C:\Users\*\Appdata\Local\Temp\*”)
Remove-Item $tempfolders -force -recurse -ErrorAction SilentlyContinue
Write-Host 'All the temp files are removed from the respective folders' -ForegroundColor Green