Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powershell

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

like image 965
urlreader Avatar asked Nov 04 '25 02:11

urlreader


1 Answers

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

like image 56
Priyanshul Govil Avatar answered Nov 07 '25 12:11

Priyanshul Govil