I'm creating a script to pull certain fields from an API. I am currently using the following script:
$test | foreach-object {
new-object psobject -Property @{
Service_Tag = $_.serviceTag
ID = $_.id
End_Date = $_.entitlements.endDate
}
} | Format-Table Service_Tag, ID, End_Date
This will output:
Service_Tag ID End_Date
----------- -- --------
Tag1 ID1 {2024-03-17T04:59:59.000001Z, 2024-03-17T04:59:59.000001Z}
Tag2 ID2 {2024-06-28T04:59:59.000001Z, 2024-06-28T04:59:59.000001Z, 2026-06-28T04:59:59.000001Z}
The issue here is that End_Date field. I only need the first object. When I export the info to a csv (which is my end goal) it shows End_Date as "System.Object[]", the other two fields look fine.
How can I select just the first entry in that End_Date object?
I've tried accessing the object similarly to an array (i.e. End_Date[0]) But that doesn't work. Presumably the object is different from a normal array.