Reputation: 6605
I'm using below script in the task scheduler to delete some files every day:
Get-ChildItem -Path "C:\Temp\*.txt" -force -ErrorAction SilentlyContinue | where {($_.LastwriteTime -lt (Get-Date).AddDays(-1) ) -and (! $_.PSIsContainer)} | Remove-Item -Verbose -Force -ErrorAction SilentlyContinue
It works. However, those files will be sent to Recycle Bin. So we still need to empty the Recycle Bin once a while. Is there a way to delete files with sending to Recycle Bin using PS script (or maybe some setting in windows)?
Thanks
Upvotes: 4
Views: 5877
Reputation: 589
remove-item
deletes the file without sending it to the recycle bin.
Upvotes: 6