I’m an amateur with PS. Not new, but not proficient. I can usually take examples and modify to my needs. But this one has me stumped.
This is my example of what I’m trying to do:
Olympics object contains the properties Year (string), CountryResults (array)
CountryResults has properties Country (string), Medals (array)
Medals has properties Gold, Silver, Bronze containing the number for each.
I’m trying to output for each country (for this example I’m not concerned about the year):
CountryResults.Country CountryResults.Medals.Gold CountryResults.Medals.Silver CountryResults.Medals.Bronze
I can create:
$a = $Olympics.CountryResults | Select-Object Country,Medals
$b = $a | Select-Object -ExpandProperty Medals
$a would give me a result like
USA @{gold=15; silver=18; bronze=0}
$b would give me a result like
15 18 0
And that goes on for every different country.
What I’m trying to do is make it display in columns:
USA 15 18 0
I’ve tried joining the 2, but that just puts the results of $b after $a.
I’ve tried:
$a = $Olympics.CountryResults | Select-Object Country,Medals.gold,Medals.silver,Medals.bronze
But I get empty results for the Medals.
I’ve tried a For-Each to make a custom object, but that didn’t work (very good chance I wrote it wrong, so if this is the answer, don’t assume I wrote mine right and please leave an example response).
I’ve searched here and while some posts come close, they’re typically looking for a certain/specific value, so I haven’t been able to translate it to my need.