如何使用 PowerShell 将文件移动到回收站? [英] How do I move a file to the Recycle Bin using PowerShell?

查看:55
本文介绍了如何使用 PowerShell 将文件移动到回收站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,当您使用 PowerShell 删除文件时,它会被永久删除.

By default when you delete a file using PowerShell it's permanently deleted.

我真的希望将已删除的项目放入回收站,就像我通过 shell 删除一样.

I would like to actually have the deleted item go to the recycle bin just like I would have happen via a shell delete.

如何在 PowerShell 中对文件对象执行此操作?

How can you do this in PowerShell on a file object?

推荐答案

这是一个更短的版本,可以减少一些工作

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")

这篇关于如何使用 PowerShell 将文件移动到回收站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆