【问题标题】:Powershell output formatting splitting the resultPowershell 输出格式拆分结果
【发布时间】:2014-05-14 06:46:54
【问题描述】:

Exchange 2013 的 powershell 中的 Test-ServiceHealth 提供以下输出:

Role                    : Mailbox Server Role
RequiredServicesRunning : True
ServicesRunning         : {IISAdmin, MSExchangeADTopology, MSExchangeDelivery, MSExchangeIS...}
ServicesNotRunning      : {}

Role                    : Client Access Server Role
RequiredServicesRunning : True
ServicesRunning         : {IISAdmin, MSExchangeADTopology, MSExchangeIMAP4, MSExchangeMailboxReplication...}
ServicesNotRunning      : {}

使用format-table 选项,我如何分离正在运行的服务,删除大括号和逗号,并将它们显示在另一个下方?

【问题讨论】:

    标签: powershell format output exchange-server


    【解决方案1】:

    您可以将数组值连接到多行字符串,然后在Format-Table 中使用-Wrap 开关,如下所示:

    [pscustomobject]@{
    Role = "Mailbox Server Role"
    RequiredServicesRunning = $True
    ServicesRunning = "IISAdmin", "MSExchangeADTopology", "MSExchangeDelivery"
    ServicesNotRunning = ""
    },[pscustomobject]@{
    Role = "Client Access Server Role"
    RequiredServicesRunning = $true
    ServicesRunning= "IISAdmin", "MSExchangeADTopology", "MSExchangeIMAP4"
    ServicesNotRunning = ""
    } | Format-Table -AutoSize -Wrap Role, RequiredServicesRunning, @{n="ServicesRunning";e={$_.ServicesRunning -join "`n"}}, @{n="ServicesNotRunning";e={$_.ServicesNotRunning -join "`n"}}
    
    Role                      RequiredServicesRunning ServicesRunning                                  ServicesNotRunning
    ----                      ----------------------- ---------------                                  ------------------
    Mailbox Server Role                          True IISAdmin                                                           
                                                      MSExchangeADTopology                                               
                                                      MSExchangeDelivery                                                 
    Client Access Server Role                    True IISAdmin                                                           
                                                      MSExchangeADTopology                                               
                                                      MSExchangeIMAP4                                                    
    

    【讨论】:

      猜你喜欢
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 2018-08-26
      • 1970-01-01
      相关资源
      最近更新 更多