PowerShell for Windows Admins

Feb 3 2010   4:40PM GMT

Disk Methods Part 2



Posted by: Richard Siddaway
Tags:
Disks

 

We recently saw how to use the Chkdsk method of the Win32_Logicaldisk class.  A quicker way to do this is to use Invoke-WmiMethod which was introduced with PowerShell 2.  This uses the path to the WMI object we are interested in – this is held in the __PATH property.  That is two underscores.  We can find the path like this

PS>  Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=’G:’" | select __PATH

__PATH
——
\\RSLAPTOP01\root\cimv2:Win32_LogicalDisk.DeviceID="G:"

We just need the value of the path which we can get like this

PS> $path = ( Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=’G:’" ).__PATH

and then we invoke the method

PS> Invoke-WmiMethod -Path $path -Name Chkdsk

Alternatively we can do it in one line like this

PS> Invoke-WmiMethod -Path $(( Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=’G:’" ).__PATH) -Name Chkdsk

Technorati Tags: ,,

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: