Powershell输出格式化拆分结果

时间:2014-05-14 06:46:55

标签: powershell format output exchange-server

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选项如何分离服务正在删除大括号&逗号并将它们显示在另一个之下?

1 个答案:

答案 0 :(得分:1)

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

[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