PowerShell命令输出作为命令输入参数问题


PowerShell交流中心PowerShell命令输出作为命令输入参数问题
0
valiantjiang asked 8 年 ago

我有一台Exchange Server 2013邮件服务器,经常会出现部分组件处于Inactive状态而使得邮件服务出线各种异常,很多时候需要手动找出处于Inactive的组件并把它置为Active状态。

我的做法是先找出Inactive的Conponent:

PS>Get-ServerComponentState -Identity idc-cas01 | ?{$_.state -eq "InActive"}

Server                                Component                            State
------                                ---------                            -----
CAS01.tima.local                      AutoDiscoverProxy                    Inactive
CAS01.tima.local                      OabProxy                             Inactive
CAS01.tima.local                      MapiProxy                            Inactive

然后逐个把它置为Active状态:

PS>Set-ServerComponentState -Identity idc-cas01 -Component AutoDiscoverProxy -State Active -Requester healthapi
PS>Set-ServerComponentState -Identity idc-cas01 -Component OabProxy -State Active -Requester healthapi
PS>Set-ServerComponentState -Identity idc-cas01 -Component MapiProxy -State Active -Requester healthapi

但是这样很不方便。

我想把它弄成脚本,每天定时跑一次。但是不知道怎么获取state为Inactive状态的Component并把它作为变量传递给Set-ServerComponentState命令。

好希望得到各位大哥的帮助,非常非常感谢!

 

 

1 Answers
1
Best Answer
Mooser Lee 管理员 answered 8 年 ago
#1.没有环境,但是应当是可以的。
Get-ServerComponentState -Identity idc-cas01 |
 where {$_.state -eq "InActive"} |
 foreach {
    Set-ServerComponentState -Identity idc-cas01 -State Active -Component $_.Component
 }

 #2.另外再试一种直接的方法,一般的PowerShell命令都是这样设计的
 Get-ServerComponentState -Identity idc-cas01 |
 where {$_.state -eq "InActive"} |
 Set-ServerComponentState -Identity idc-cas01 -State Active
valiantjiang replied 8 年 ago

好的我试下。现在服务都是Active状态,我会密切关注。非常感谢!