我尝试在 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
但它不起作用。我收到 $Columns 错误:
InvalidArgument: (:) [Format-Table], NotSupportedException
我找到了一个示例https://technet.microsoft.com/de-de/library/ee692794.aspx
$a = @{Label="ColA"; Alignment='right'}, @{Label="ColB"; Alignment='right'}
...
Format-Table @a ...
如何动态创建这样的 $a 列表?