CSV Lookup to a String instead of an Object in PowerShell [duplicate]
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 to a new variable. how can i achieve this in powershell. Thanks
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 }