Select an Item from List in PowerShell

后端 未结 1 1829
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 02:57

I am making an api call using PowerShell. I get 3 outputs as results from the call.

ID : 1
Name :Abc
Location : London

I want to pass the ID

相关标签:
1条回答
  • 2020-12-12 03:32

    You can either use the . member access operator:

    $ID = (Call-ThatReturnsObject).ID
    

    Or Select-Object -ExpandProperty:

    $ID = Call-ThatReturnsObject |Select-Object -ExpandProperty ID
    

    Or ForEach-Object:

    $ID = Call-ThatReturnsObject |ForEach-Object -MemberName ID
    # or 
    $ID = Call-ThatReturnsObject |ForEach-Object { $_.ID }
    
    0 讨论(0)
提交回复
热议问题