Extracting bits from hashtable property

This topic contains 6 replies, has 2 voices, and was last updated by  JC 2 weeks, 1 day ago.

  • Author
    Posts
  • #102037

    JC
    Participant

    I have a variable that stores some properties like prop1, prop2, prop3... where a few are in form of hashtables. I'd need to select a couple of the properties stored in the variable and some pieces of the hashtable. The hashtable is in form of e.g. prop2: {@{label1=value1},@{label2=value2},....}
    when I try
    $var | select prop1 -expandproperty prop2
    I'm not getting the output I need. I only want to get value1. What would be the right way to extract the properties out of ?

  • #102043

    Jon
    Participant
    $var.item(0)
  • #102046

    JC
    Participant

    Thanks Jon but in short I get PSCustomObject doesn't contain method item.

  • #102049

    Jon
    Participant

    So you don't have a normal hashtable then.

    To be able to help any further, you'll need to post your code. You can also pipe your data to get-member and look at the information you can access.

  • #102052

    JC
    Participant

    $var is of PSCustomObject type where prop2 is System.Object[]. The results come from Get-HPiLOHealthSummary commandlet by HPE.
    I managed to get a bit further going
    $vars | select prop1, @{name="prop2";expression={[string]::join(";",($_.prop2))}}
    but my prop2 now displays as
    @{label=value};@{label=value}
    how to get rid of @{} then?

  • #102056

    Jon
    Participant
  • #102058

    JC
    Participant

    Wow! and exact match. Excellent googling skills Jon 🙂 Many thanks

You must be logged in to reply to this topic.