Search code examples
powershellpowershell-3.0

Remove-Item not working in Windows Temp folder


I have a server with an incredibly overloaded Windows/Temp folder. So, I wanted to run a simple Powershell script to clear it out (I'm talking tens of thousands of .tmp and .bak files that are over a year old). Below is the code:

Remove-Item C:\Windows\Temp\* -Include .txt,.bak,.tmp -WhatIf

I tried removing the -WhatIf as well (I just had that in there because I was playing around with some stuff) and nothing happens. It's so simple I'm almost definitely missing something simple.


Solution

  • Missing wildcard on the -include:

    Remove-Item C:\Windows\Temp\* -Include *.txt, *.bak, *.tmp -WhatIf