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?
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?
JScript:
function main()
{
var Shell =3D WScript.CreateObject("Shell.Application");
var Folder =3D Shell.Namespace("<path to file>");
var Item =3D Folder.ParseName("<name of file>");
Item.InvokeVerb("delete");
}
http://www.eggheadcafe.com/software/aspnet/30890097/send-file-to-recycle-bin.aspx
It works in PowerShell pretty much the same way as Chris Ballance's solution in JScript:
$shell = new-object -comobject "Shell.Application"
$folder = $shell.Namespace("<path to file>")
$item = $folder.ParseName("<name of file>")
$item.InvokeVerb("delete")
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")
The solution above requires a confirmation for each file. Is there an alternative?