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

后端 未结 7 1007
攒了一身酷
攒了一身酷 2020-12-07 20:19

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

7条回答
  •  旧时难觅i
    2020-12-07 20:58

    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)

提交回复
热议问题