powershellrecycle-bin

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


When using the rm command to delete files in Powershell, they are permanently deleted.

Instead of this, I would like to have the deleted item go to the recycle bin, like what happens when files are deleted through the UI.

How can you do this in PowerShell?


Solution

  • Here is a shorter version that reduces a bit of work

    $path = "<path to file>"
    $shell = new-object -comobject "Shell.Application"
    $item = $shell.Namespace(0).ParseName("$path")
    $item.InvokeVerb("delete")