I have the following PowerShell command which returns all sorts of properties about disk drives attached to the system:

Get-WmiObject -Class Win32_Volume | Where-Object {$_.DeviceID -like "\\?\*"}

I'm only interested in the DriveLetter and DeviceID properties and would like them to be returned in a table something like this:

DriveLetter    DeviceID
C:             \\?\Volume{5b982fce-d9e5-11e1-9c28-806e6f6e6963}\
D:             \\?\Volume{e9820c98-d688-11e1-a45f-001e673f1fc5}\

I know that I can surround my original command and use the dot operator to return one of my properties at a time:

(Get-WmiObject -Class Win32_Volume | Where-Object {$_.DeviceID -like "\\?\*"}).DriveLetter

Which in return produces:


But I don't know how to write a single statement that will return two (or more) properties as a table. If it's not possible to accomplish this with a single statement, what am I to do in order to produce the desired table output?

I have searched Google for an answer but because I'm pretty new to PowerShell I probably am not phrasing my search terms correctly and thus not getting what I imagine is the simple answer to my question.


Try this:

Get-WmiObject -Class Win32_Volume | Where-Object {$_.DeviceID -like "\\?\*"} | Select-Object -Property DriveLetter,DeviceID

Use Get-Help Select-Object -Detailed for more information.


Just format the output using the Format-Table cmdlet:

Get-WmiObject -Class Win32_Volume | 
Where-Object {$_.DeviceID -like "\\?\*"} | 
Format-Table DriveLetter,DeviceID

Generates output:

DriveLetter                                                            DeviceID                                                              
-----------                                                            --------                                                              
C:                                                                     \\?\Volume{118e4062-2eba-4f35-9b1b-015c3c1087dc}\                     

Make sure you understand how the formatting cmdlets (ft, fl etc) integrates with the objects on the pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.