Each PSCustomObject has a few hidden properties:
$Stats |Get-Member -Force
Name MemberType Definition
---- ---------- ----------
pstypenames CodeProperty System.Collections.ObjectModel.Collection`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] pstypenames{get=PSTypeNames;}
psadapted MemberSet psadapted {ToString, GetType, Equals, GetHashCode}
psbase MemberSet psbase {ToString, GetType, Equals, GetHashCode}
psextended MemberSet psextended {Id, Name, Country, EMail, Age, ReportsTo}
psobject MemberSet psobject {BaseObject, Members, Properties, Methods, ImmediateBaseObject, TypeNames, get_BaseObject, get_Members, get_Properties, get_Methods, get_ImmediateBaseObject, get_TypeNames, ToString, Copy, CompareTo, Equals, GetHash…
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
... NoteProperty ...
Where the PSObject property contains a Properties property containing child properties along with the Name and the Value of each $Stats property.
In other words, to find out the name of the first $Stats[0] property (aka first column), you can do:
$Stats[0].PSObject.Properties.Name[0]
ColumnHeader
And to retrieve all the values of that column:
$ColumnName = $Stats[0].PSObject.Properties.Name[0]
$Stats.$ColumnName
Or:
$Stats.($Stats[0].PSObject.Properties.Name[0])