1

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:

C:
D:

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.

2

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.

0
2

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}\                     
                                                                       \\?\Volume{e2a184aa-dac8-4196-80c6-fd8c7662e377}\                     
                                                                       \\?\Volume{33697e48-1197-464c-8553-cef00429e5a4}\                     

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.