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
remove-item deletes the file without sending it to the recycle bin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With