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?
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.
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)
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