How to delete all temp files using powershell

Mshah17 picture Mshah17 · Jul 26, 2018 · Viewed 10.1k times · Source

Anyone knows how to delete all temp files using powershell.

Get-ChildItem $env:TEMP\TEMP | Remove-Item -confirm:$false -force -Recurse

I tired this code but it couldn't work. Can you suggest me any better way to perform the same.

Answer

TobyU picture TobyU · Jul 26, 2018

If you don't want to see any errors, you could use the -ErrorAction switch like this:

Remove-Item -Path $env:TEMP -Recurse -Force -ErrorAction SilentlyContinue