Desc :
创建自己的命令的 输出格式
1 格式化 : 让输出更加美观
输出定制格式的方式
2 默认格式
PS C:windowssystem32> echo $PSHOME C:windowsSystem32WindowsPowerShellv1.0
在 PowerShell 的安装路径下, *format.ps1xml , 其中,对进程对象的格式化目录在 “DotNetTypes.format.ps1xml” 中
PS C:> cd $PSHOME PS C:windowsSystem32WindowsPowerShellv1.0> ls 目录: C:windowsSystem32WindowsPowerShellv1.0 Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 2016/6/2 18:01 en d---- 2016/6/9 13:39 en-US d---- 2016/6/2 18:01 Examples d---- 2016/6/2 18:01 Modules d---- 2016/6/2 18:01 Schemas d---- 2016/6/2 18:01 SessionConfig d---- 2016/6/9 13:38 zh-CN d---- 2016/6/2 18:01 zh-HANS d---- 2016/6/2 18:01 zh-HANT d---- 2016/6/2 18:01 zh-TW
3 格式化表格
1) -autoSize : 会根据你的屏幕 生成和 填充表格 , 使表格更加紧凑
2) -property : 列出想要在 表格中,显示的列, * 所有, ID,Name
3) -groupBy : 当指定的属性值变更时,创建一个具有 新列头的结果集,这个 参数,zhi
4) -wrap : 如果 Shell 需要把列的信息阶段,会在列为带上 .... , 以便 标识信息被阶段
4 格式化列表 Format-List
Fl == Format-List
与 Gm 的区别, 同时显示这些属性的值
Get-Service | Fl *
5 宽度的格式化
Get-Process | Format-Wide name -col 4 [ -columns ]
只查看 对象的Name 属性,默认值显示 2列, 但 -columns 可以 指定更多的列
6 定制列 和列表的记录
Get-Process | Format-Table Name ,
@{n='VM(MB)' ; e={$_.VM /1MB -as {int}}} -autosize
7 输出到文件, 打印机 或者 主机上
Get-Service | Format-Wide
PS C:windowssystem32> Get-Command -Verb Out* CommandType Name ModuleName ----------- ---- ---------- Cmdlet Out-Default Microsoft.PowerShell.Core Cmdlet Out-File Microsoft.PowerShell.Utility Cmdlet Out-GridView Microsoft.PowerShell.Utility Cmdlet Out-Host Microsoft.PowerShell.Core Cmdlet Out-Null Microsoft.PowerShell.Core Cmdlet Out-Printer Microsoft.PowerShell.Utility Cmdlet Out-String Microsoft.PowerShell.Utility
Out-File , Out-Printer , Out-Host 只有这三个 Out- cmdlet 才能 跟在 Format- cmdlet 后面
8 另外一个输出: 网格
Get-Service | Out-GridView
[ Note ] Out-GridView 不接收 Format- cmdlet 的输出, 仅 接受其他 cmdlet 的输出