I try to format two dimensional table in PowerShell:
$ContentServeres.Keys | Sort-Object | Foreach-Object {
$Columns += @{Label=$_; Alignment='right'}
}
$ClientServeres.Keys | Sort-Object | Foreach-Object {
PROCESS {
$obj = $ClientServeres.Get_Item($_)
$serverOutObj = New-Object PSObject
$serverOutObj | Add-Member NoteProperty Client ("$($_)`t`t")
$ContentServeres.Keys | Sort-Object | Foreach-Object {
$serv = $obj.Get_Item($_)
$serverOutObj | Add-Member NoteProperty $_ ("{0:N0}" -f $serv.SumLength)
}
Write-Output $serverOutObj
}
} | Format-Table $Columns -AutoSize
But it doesn't work. I get error with $Columns:
InvalidArgument: (:) [Format-Table], NotSupportedException
I've found a Sample https://technet.microsoft.com/de-de/library/ee692794.aspx
$a = @{Label="ColA"; Alignment='right'}, @{Label="ColB"; Alignment='right'}
...
Format-Table @a ...
How can I dynamically create such $a list?
$Columns = $ContentServeres.Keys | Sort-Object | Foreach-Object { @{Label=$_; Alignment='right'} }