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.
Delete Files in PowerShell using Remove-Item cmdlet In PowerShell, the Remove-Item cmdlet deletes one or more items from the list. It utilizes the path of a file for the deletion process. Using the “Remove-Item” command, you can delete files, folders, variables, aliases, registry keys, etc.
Yes, it's safe to delete temporary files from Windows. Most of the time, they'll be deleted automatically — if they're not, you can go in and delete them yourself without any worries.
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
To empty TEMP folder and leave the folder in place, you should use this command:
Remove-Item $env:TEMP\* -Recurse
If you don't want to type so much, you can use also shorter version:
rm $env:TEMP\* -r
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With