Ahh, so the commands inside the loop don't output text, they return objects directly on the pipeline. You essentially end up with a list of controller, ontapi version, controller, ontapi version, and so on. Because you have a select statement in there and multiple types in the output, PowerShell is getting confused and doesn't know how to format the objects.
Instead, one option is to use the Select-Object cmdlet to combine the controller and Ontapi Version into a single object:
$hostnames = @("10.61.169.28", "10.61.165.227")
foreach ($hostname in $hostnames)
{
$cntlr = Connect-NaController $hostname
Get-NaSystemOntapiVersion |
select @{Name="Name";Expression={$cntlr.Name}},
@{Name="Address";Expression={$cntlr.Address}},
MajorVersion, MinorVersion
}
which outputs this:
Name | Address | MajorVersion | MinorVersion |
---- | ------- | ------------ | ------------ |
10.61.169.28 | 10.61.169.28 | 1 | 13 |
10.61.165.227 | 10.61.165.227 | 1 | 7 |
Of course this example is a bit contrived since the controller object already includes an OntapiVersion property, but it would apply similarly to any other information you gather per controller...
Hope that helps!