使用Format命令格式化powershell输出,常用的命令如下:
例如:
Get-Process -Name powershell|Format-Wide
Get-Process -Name powershell| Format-wide -Property Id
例如:
Get-Process -Name powershell|Format-List -Property *
例如:
Get-Process -Name powershell|Format-Table -Property Path,Name,Id,Company
通过指定AutoSize参数可以改善这一现象,使用AutoSize参数后仅最后一列可能会截断,当然,最后一列以后的列会因为无法现实而被移除,同时powershell会通过控制台向用户发出警告,告知用户某些列被移除。
例如:
Get-Process -Name powershell|Format-Table -Property Path,Name,Id,Company -AutoSize
Get-Process -Name powershell|Format-Table -Property * -AutoSize
还可以使用参数GroupBy来分组显示输出结果,-GroupBy指定的属性即为分组依据。
例如:
Get-Process -Name powershell|Format-Table -AutoSize
-Property Path,Name,Id,Company -GroupBy Company
4) Format-Custom:使用预定义的可选视图格式化输出。可以在Windows Powershell目录下查看*format.PS1XML文件来决定可以选用的视图。也可以创建自己的.PS1XML视图文件。
为了得到我们想要的输出,我们常常要指定属性值(-Property)来确定输出列,要查看一个对象的属性,可以发送命令的输出到Get-Member:
例如:
Get-Process | Get-Member -MemberType *Property
联系客服