How do I get the VALUE of a Property (in an object)??

I have the following chain of commands:

Get-WmiObject win32_logicaldisk | Where-Object VolumeName -eq “DDRIVE” | Select-Object -property DeviceID

When executed, it produces 3 lines of output (actually 4, including the first line of blanks):



What cmdlet, function, or ??? can I use to extract just the value of the DeviceID property, which in this case is D: ?
This is so I can assign it to a variable which will be concatenated to a specific folder to form a complete path name.
Get-ItemPropertyValue can’t seem to do the job.
Any advice, tips or pointers would be highly appreciated.

 Get-WmiObject win32_logicaldisk | Where-Object VolumeName -eq "DDRIVE" | % { write-output $_.DeviceID } 

If I am not mistaken, all volume names are unique unless blank.

(Get-CimInstance -ClassName win32_logicaldisk -Filter "VolumeName='DDRIVE'").DeviceID
(Get-WmiObject -Class win32_logicaldisk -Filter "VolumeName='DDRIVE'").DeviceID

… or the pure Powershell way …
instead of

Select-Object -property DeviceID
you do
Select-Object -ExpandProperty DeviceID

Many thanks, Mr/Ms Bakhtyar … your solution not only worked, but it made me realize why Get-ItemPropertyValue (which I was struggling to “make it work”) does not work.

Yes, you are right. Many thanks for giving 2 ways of doing the same thing.
While I do not yet know the finer differences between WmiObject and CmiInstance, I hope to read about them in order to appreciate which one is more appropriate under certain specific conditions, and other finer aspects as efficiency, etc…
My sincerest thanks for your technical tip, it has enhanced my learning process.

Thank you! It works perfectly. The documentation on the -ExpandProperty parameter is limited, so I do not claim to understand what it is really doing behind the scenes. All I know is that in the object-oriented world of Poweershell (which is great!) there are other “new properties” - e.g., AliasProperty,NoteProperty - that have been added to the original Property concept in object-oriented approaches. Would be grateful if you can point me to references/sites/docs that explain the -ExpandProperty in more detail. Thanks again.