【发布时间】:2014-06-14 09:22:36
【问题描述】:
我正在使用Format-Table 编写一个在列中发出输出的脚本,并且无法显示超过 9 个(无论有无 -AutoSize 参数)。
以防万一不是我的错,只是一些没有记录的东西:
Format-Table 最多可以显示多少列?
如果它未绑定,我将从我的脚本中提炼出一个可重现的小案例。
我正在使用 PowerShell 4.0,并创建要列出的对象,如下所示:
New-Object PSCustomObject -Property ([Ordered] @{
"BDS #" = $bdsVersion
"HKCU" = $hkcuBasePath
"HKLM" = $hklmBasePath
"Name" = $fullName
"CompilerVersion" = $compilerVersion
"RTLVersion" = $rtlVersion
"Define" = $define
"Characterset" = $characterSet
"Architectures" = $architecture
"Frameworks" = $framework
"DllSuffix" = $dllSuffix
})
即使我的控制台窗口足够宽(300 个字符宽),DllSuffix 列也不会显示。
编辑:
根据Cole9350 的suggestion,我添加了-Wrap to the -AutoSize argument 来格式化表格,但仍然失败:
function Get-BDS-ProductSummaries {
$bdsVersions = Get-BDS-Versions
$bdsVersions | ForEach-Object {
$summary = Get-BDS-ProductSummary $_
$summary
} | Format-Table -AutoSize -Wrap
# http://blogs.technet.com/b/nexthop/archive/2011/03/21/psformatorselect.aspx
Write-Host "Slash separated values like xxx/yyy means native/.NET"
}
我从脚本的“主要”部分调用此函数:
$args | ForEach-Object {
$arg = $_
switch ($arg) {
# ...
'ProductSummaries' {
Write-Host "Product Summaries:"
Get-BDS-ProductSummaries
}
# ...
}
$anyArg = $True
}
解释-Wrap 与-Format-Table 组合的链接也表明有时并非所有列都会显示,但没有说明在什么情况下。
所以我正在寻找指导:什么时候不会全部显示出来?
我什至重新排序了一些字段,并将 HKCU/HKLM 路径合并为一个字段并放在最后:
New-Object PSCustomObject -Property ([Ordered] @{
"BDS #" = $bdsVersion
"Name" = $fullName
"CompilerVersion" = $compilerVersion
"RTLVersion" = $rtlVersion
"Define" = $define
"Characterset" = $characterSet
"Architectures" = $architecture
"Frameworks" = $framework
"DllSuffix" = $dllSuffix
"ProjectVersion" = $projectVersion
# "HKCU" = $hkcuBasePath
# "HKLM" = $hklmBasePath
"HKCU/HKLM registry path" = $basePath
})
它显示了一个 165 个字符宽的表格(而我的控制台窗口是 300 个字符宽):
Product Summaries:
BDS # Name CompilerVersion RTLVersion Define Characterset Architectures Frameworks DllSuffix ProjectVersion
----- ---- --------------- ---------- ------ ------------ ------------- ---------- --------- --------------
1 Borland C# Builder 1 C# C# C# Unicode C# .NET 1 .NET ???? ????
2 Borland Delphi 8 none/16.0 none/16.0 VER160/VER160 Ansi/Unicode Win32;.NET 1 VCL/.NET 80 80
3 Borland Delphi 2005 17.0/17.0 17.0/17.0 VER170/VER170 Ansi/Unicode Win32;.NET 1 VCL/.NET 90 ????
4 Borland Delphi 2006 18.0/18.0 18.0/18.0 VER180/VER180 Ansi/Unicode Win32;.NET 2 VCL/.NET 100 ????
5 Borland Delphi 2007 18.5/19.0 18.0/19.0 VER180&VER185/VER190 Ansi/Unicode Win32;.NET 2 VCL/.NET 100 ????
6 CodeGear Delphi 2009 20.0 20.0 VER200 Unicode Win32 VCL 120 11.1;12.0
7 CodeGear Delphi 2010 21.0 21.0 VER210 Unicode Win32 VCL 140 12.0
8 Embarcadero Delphi XE 22.0 22.0 VER220 Unicode Win32 VCL 150 12.2;12.3
9 Embarcadero Delphi XE2 23.0 23.0 VER230 Unicode Win32;Win64 VCL 160 13.4
10 Embarcadero Delphi XE3 24.0 24.0 VER240 Unicode Win32;Win64;OSX32 VCL;FMX1 170 14.3;14.4
11 Embarcadero Delphi XE4 25.0 25.0 VER250 Unicode Win32;Win64;OSX32;iOS-Arm VCL;FMX2 180 14.6
12 Embarcadero Delphi XE5 26.0 26.0 VER260 Unicode Win32;Win64;OSX32;iOS-Arm;Android-Arm VCL;FMX2 190 15.1
13 Embarcadero Appmethod 1 ???? ???? ???? Unicode ???? FMX2 ???? ????
14 Embarcadero Delphi XE6 27.0 27.0 VER270 Unicode Win32;Win64;OSX32;iOS-Arm;Android-Arm VCL;FMX2 200 15.4
15 Embarcadero Appmethod 2 ???? ???? ???? Unicode ???? FMX2 ???? ????
随着路径更靠近开头,输出宽度为 181 个字符:
BDS # HKCU/HKLM registry path Name CompilerVersion RTLVersion Define Characterset Architectures Frameworks DllSuffix
----- ----------------------- ---- --------------- ---------- ------ ------------ ------------- ---------- ---------
有-Wrap,但没有-AutoSize,最后一列也不显示。
当离开Format-Table 时,它会显示所有字段,因此New-Object PSCustomObject -Property 会产生所有属性:
BDS # : 14
HKCU/HKLM registry path : \Software\Embarcadero\BDS\14.0
Name : Embarcadero Delphi XE6
CompilerVersion : 27.0
RTLVersion : 27.0
Define : VER270
Characterset : Unicode
Architectures : Win32;Win64;OSX32;iOS-Arm;Android-Arm
Frameworks : VCL;FMX2
DllSuffix : 200
ProjectVersion : 15.4
【问题讨论】:
-
这不是设定的列数,它取决于每列中值的最大大小。只需使用
-wrap参数或Select -expandProperty...无论哪种方式,这只是用于控制台输出 -
@Cole9350 您应该将您的评论转换为问题的答案。
-
@Cole9350 我试过了。不起作用。刚刚用我尝试的方法编辑了我的答案。