PowerShell for Windows Admins

Feb 3 2010   4:40PM GMT

Disk Methods Part 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


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


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.

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: