urlreader
urlreader

Reputation: 6605

Using PS: How to force delete files without sending to Recycle Bin?

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

Answers (1)

Priyanshul Govil
Priyanshul Govil

Reputation: 589

remove-item deletes the file without sending it to the recycle bin.

Upvotes: 6

Related Questions