Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 421
Omar Shahine Avatar asked Feb 02 '09 01:02

Omar Shahine


People also ask

Why can't I move a file to the Recycle Bin?

On your desktop, right-click the Recycle Bin icon and then click Properties. When the Recycle Bin dialog box pops up, ensure that the radio button under Settings for selected location is on Custom size and not on Don't move files to the Recycle Bin. Confirm this action by clicking Apply. Click OK to close the window.


1 Answers

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)

like image 198
John Pankowicz Avatar answered Sep 18 '22 16:09

John Pankowicz