Disk Methods Part 2
Posted by: 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
__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




