【问题标题】:Exchange Remote Powershell gets sporadic 'Broken' stateExchange Remote Powershell 获得零星的“损坏”状态
【发布时间】:2015-08-17 11:57:38
【问题描述】:

我正在尝试通过 Windows Powershell 从远程 Exchange Server 接收所有 TransportAgent 的状态。

我偶尔收到一个错误,即The session state is Broken。一旦它被打破,我需要创建一个新的会话

下面是我正在使用的命令列表(按正确顺序)

# Build the PSSession for Exchange
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<SERVER>/PowerShell/ -Authentication Default
# Invoke the command 'Get-TransportAgent' on the remote PSSession
Invoke-Command $Session {Get-TransportAgent}
# Result when there is NO ERROR
Identity                                           Enabled         Priority        PSComputerName
--------                                           -------         --------        --------------
Transport Rule Agent                               True            1               <SERVER>
Malware Agent                                      True            2               <SERVER>
Text Messaging Routing Agent                       True            3               <SERVER>
Text Messaging Delivery Agent                      True            4               <SERVER>

当我重复命令Invoke-Command $Session {Get-TransportAgent} 时,偶尔会出现以下错误:

Invoke-Command : Because the session state for session Session9, <GUID-REMOVED>, <SERVER> is not equal to Open, you cannot run a command  in the session.  The session state is Broken. At line:1 char:1

更新

在 SessionOption 中添加 IdleTimeout 后,我​​收到以下错误,然后是 Session is Broken

Invoke-Command $Session {Get-TransportAgent}
Starting a command on the remote server failed with the following error
message : The I/O operation has been aborted because of either a thread exit or an application request. For more information, see the about_Remote_Troubleshooting
Help topic.
+ CategoryInfo          : OperationStopped: (<SERVER>:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName        : <SERVER>

问题:为什么会出现错误以及如何解决?

【问题讨论】:

    标签: powershell exchange-server powershell-remoting


    【解决方案1】:

    您的会话很可能超时。要进行补救,请创建一个增加会话超时值的PSSessionOption 对象,然后您可以将其提供给New-PSSession cmdlet。默认超时时间为 60000 毫秒(1 分钟),如果您正在运行包含异步请求的扩展脚本或工作时间很长,这可能会非常小。

    $so = New-PSSessionOption -IdleTimeout 600000
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<SERVER>/PowerShell/ -Authentication Default -SessionOption $so
    

    SessionOption 对象将使您的$session 在最后一次命令执行后保持打开状态 10 分钟。

    编辑:在阅读有关 Powershell 远程会话状态的手册后,我发现 Broken 是一种异常状态,它不是由空闲或其他本地操作引起的,而是一种丢失的迹象所涉及的主机之间的连接,或在服务器端运行“wsmprovhost”的问题。您应该调查您的操作系统和网络是否正常。脚本仍然可以处理此类错误,为此您应该检查会话状态,如果不是 Opened,请重新打开会话。

    if ($session.state -ne "Opened") { 
        Write-Host "The session went into $($session.state) state! Reinitializing!"
        $session=New-PSSession <arguments skipped>
    }
    

    不过,如果重新连接尝试会引发超时,那么请退出您的脚本,因为在没有连接的情况下您将无法再进行任何远程处理。

    【讨论】:

    • 不到 10 分钟它仍然给我错误(请参阅我更新的问题),我也会检查其他 SessionOptions - 谢谢
    • 我已经设法发现,如果 PSSession 的任一侧出现任何类型的网络断开连接,会话就会中断。您只能调试本地和远程服务器之间的连接。可以对脚本进行修改,因此如果 $session.state 不是 open,您可以指示脚本重新创建会话对象。
    • 我发现远程服务器连接不良(往返、网络延迟问题),这会导致“损坏”状态。 - 我将通过使用 -NoEncryption 和 -NoCompression 标志给它最后一次机会。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2013-06-20
    • 2011-12-15
    • 2018-08-07
    • 2017-03-31
    • 2023-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多