How do I move a file to the Recycle Bin using PowerShell?

By default when you delete a file using PowerShell it's permanently deleted.

I would like to actually have the deleted item go to the recycle bin just like I would have happen via a shell delete.

How can you do this in PowerShell on a file object?


If you don't want to always see the confirmation prompt, use the following:

Add-Type -AssemblyName Microsoft.VisualBasic
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('d:\foo.txt','OnlyErrorDialogs','SendToRecycleBin')

(solution courtesy of Shay Levy)


2017 answer: use the Recycle module

Install-Module -Name Recycle

Then run:

Remove-ItemSafely file

I like to make an alias called trash for this.