PowerShell the way to remove files to the Recycle Bin _powershell

Source: Internet
Author: User

A colleague worked hard for one months to finish the design plan, because of his careless, directly from the company's shared file server deleted, can not be recovered. I also tried to build a shared folder, through the Explorer deleted, but also in the Recycle Bin can not find, so as to understand the female man's difficulties.

We usually use the PowerShell remove-item command to delete the file, but also belong to the total deletion. In fact, really, if I can, I would like to Zhaoyuan fast food 6 killers, execute the Remove command, no, direct kill command.

So how do you safely delete files to the Recycle Bin in PowerShell? Obviously you need to invoke the COM component of Windows:

Copy Code code as follows:
$testFile = "Jb51.net"
Dir | Out-file $testFile
$shell = New-object-comobject "Shell.Application"
$item = $shell. Namespace (0). ParseName ((Resolve-path $testFile). Path)
$item. Invokeverb ("delete")

Note the 4th line, be sure to use the absolute path, use relative path may be an error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.