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

后端 未结 7 989
攒了一身酷
攒了一身酷 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条回答
  •  太阳男子
    2020-12-07 21:15

    Remove file to RecycleBin:

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

    Remove folder to RecycleBin:

    Add-Type -AssemblyName Microsoft.VisualBasic
    [Microsoft.VisualBasic.FileIO.FileSystem]::Deletedirectory('e:\test\testfolder','OnlyErrorDialogs','SendToRecycleBin')
    

提交回复
热议问题