I want to deleted all the files in the temp folder... any .zip files , .txt files and any folder files including whatever is inside each of those folders (everything). I thought this would be simple but so far my script keeps getting the confirmation pop-up asking if I want to delete all these child items. I tried using -confirm:$false
but that doesn't seem to work. I appreciate any suggestions. Thank you.
$list = Get-ChildItem -directory "C:\temp\*" -Include * -Name
get-childitem c:\temp -Include @(get-content $list) | Remove-Item -Force -whatif
I tried using the -confirm:$false
argument as well as the -force
with no luck.
You want -path vs -directory.
#Looking for Temp under Windows:
$list = (Get-ChildItem -path "C:\*\Temp*\*.*").FullName | Remove-Item -Force
#Looking for Temp under Root:
$list = (Get-ChildItem -path "C:\Temp*\*.*").FullName | Remove-Item -Force
If your Temp dirs have subs you could also add the -recurse switch.