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
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 }