PowerShell for Windows Admins

Jul 7 2013   1:01PM GMT

Deleting a file with WMI

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Following on from the last post this is how you can delete a file.

Use the same file structure as previously

This time you need to use the CIM_DataFile class. It’s one of the few classes I’ve found that doesn’t have a Win32_ equivalent.

The class has a Delete method. Assuming you know the full path to the file

Get-CimInstance -ClassName CIM_DataFile -Filter “Name=’C:\\Expendable\\Target1\\proc.txt’ ” |
Invoke-CimMethod -MethodName Delete

You can perform most actions on files and folders using WMI but you can’t create a file or a folder

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: