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

Welcome Forums General PowerShell Q&A How do I get the VALUE of a Property (in an object)??

This topic contains 6 replies, has 4 voices, and was last updated by

9 months, 2 weeks ago.

  • Author
  • #102092

    Points: 424
    Rank: Contributor

    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.

  • #102094

    Points: 0
    Rank: Member
     Get-WmiObject win32_logicaldisk | Where-Object VolumeName -eq "DDRIVE" | % { write-output $_.DeviceID } 
    • #102142

      Points: 424
      Rank: Contributor

      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.

  • #102095

    Points: 58
    Rank: Member

    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
    • #102143

      Points: 424
      Rank: Contributor

      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.

  • #102098

    Points: 1,184
    Helping Hand
    Rank: Community Hero

    .... or the pure Powershell way ...
    instead of

    Select-Object -property DeviceID

    you do

    Select-Object -ExpandProperty DeviceID
    • #102146

      Points: 424
      Rank: Contributor

      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.

The topic ‘How do I get the VALUE of a Property (in an object)??’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort