我们在使用Format-Table去显示输出信息的时候,通常会发现如果某个属性字段比较长,则无法正常全部显示,如下。
PS> Get-Process -Name powershell | Format-Table -Property Company,Name,Id,Path -AutoSize
Company Name Id Path
------- ---- -- ----
Microsoft Corporation powershell 2836 C:\Program Files\Windows PowerShell\v1...
这里面涉及到一个很重要的细节是,Format-Table 命令假定属性距离属性列表的开头越近,则该属性越重要。 因此,它会尝试完整显示离列表开头最近的那些属性。 如果 Format-Table 命令无法显示所有属性,它将从显示中删除某些列,并发出警告。如果你使名称变成列表中的最后一个属性,便可以看到这一行为:
PS> Get-Process -Name powershell | Format-Table -Property Company,Path,Id,Name -AutoSize
WARNING: column "Name" does not fit into the display and was removed.
Company Path I
d
------- ---- -
Microsoft Corporation C:\Program Files\Windows PowerShell\v1.0\powershell.exe 6
你还可以通过使用 Wrap 参数让较长的 Format-Table 数据在其显示列中自动换行。 仅使用 Wrap 参数不一定会实现所需的操作,因为如