refer to custom expression property on same select-object

Welcome Forums General PowerShell Q&A refer to custom expression property on same select-object

Viewing 4 reply threads
  • Author
    • #192130
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      can you help me with this simple example script?
      How do I refer to “custom expression property” on single one “select-object”?

      I would like: **single “select-object”**

      Get-Process | Select-Object Id,
      @{name=”MyProp”; expression={$}},
      @{name=”MyPropRef”; expression={$_.MyProp}}

      …but third property “MyPropRef” is not displayed!

      Id MyProp MyPropRef
      — —— ———
      3780 3780

      While with *double select-object piped*, “MyPropRef” is displayed

      Get-Process | Select-Object Id,
      @{name=”MyProp”; expression={$}} | Select-Object *,
      @{name=”MyPropRef”; expression={$_.MyProp}}

      Id MyProp MyPropRef
      — —— ———
      3780 3780 3780


    • #192151
      Topics: 11
      Replies: 127
      Points: 762
      Helping Hand
      Rank: Major Contributor

      What is the actual property name and/or data you’re expecting?

      To find the correct property name, do Get-Process | Get-Member and see what the actual property name is.

      And depending on the property, sometimes it may not have anything to output, hence the blank value.

    • #192172
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,781
      Helping Hand
      Rank: Community Hero

      They are called as calcluated properties.

      Here you are using ID as MYProp and MyPropRef, hence you can use the same expression for both Calculated property. You will have to sue multiple select object if you want to create a calculated property from another calculated property without the first one being created its not available for the second expression.

    • #192190
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP
    • #192358
      Topics: 0
      Replies: 8
      Points: 104
      Rank: Participant

      Would reference ID property again from the pipeline do the trick?

Viewing 4 reply threads
  • The topic ‘refer to custom expression property on same select-object’ is closed to new replies.