zoukankan      html  css  js  c++  java
  • Powershell格式化输出

    使用Format命令格式化powershell输出,常用的命令如下:

    1. Format-Wide:每个对象仅有一个属性值被显示。默认情况下输出默认属性,也可以通过指定-Property参数来输出其他属性

    例如:

    Get-Process -Name powershell|Format-Wide

    Get-Process -Name powershell| Format-wide -Property Id

    1. Format-List:将对象输出格式化为属性列表。如果想让所有属性均在列表中输出,可使用通配符*来指定属性值

    例如:

    Get-Process -Name powershell|Format-List -Property *

    1. Format-Table:将输出格式化为一张表格。这是默认的输出格式,也就是说即使不指定Format-Table,powershell对对象的输出也为表格形式,此输出格式有一个缺点,就是当列宽不够时,文字会被截断(truncated)。

    例如:

    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

  • 相关阅读:
    转发 微博 Qzone 微信 草根创业英雄时代落幕:贾跃亭戴威们一去不复返
    python 发送大Json格式数据
    python post json数据
    python post 参数
    IntelliJ Idea 常用10款插件(提高开发效率)
    IDEA操作技巧:一些常用且实用的插件
    nacos
    Sentinel 与 Hystrix 的对比
    阿里启动新项目:Nacos,比 Eureka 更强!
    D3.js学习(一)
  • 原文地址:https://www.cnblogs.com/ITGirlXiaoXiao/p/2624851.html
Copyright © 2011-2022 走看看