Exchange Remote Powershell获得零星的“破碎”状态

时间:2015-06-03 10:19:35

标签: powershell exchange-server powershell-remoting

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

我偶尔收到错误console.log($scope.ExistingreportDetails.repositoryFileDto[0].aclNode); 。一旦它坏了我需要创建一个新的Session

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

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}

更新

在SessionOption中添加IdleTimeout后,我接收到以下错误,然后会话被破坏

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

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

1 个答案:

答案 0 :(得分:4)

您的会话很可能超时。要解决此问题,请创建一个具有增加的会话超时值的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>
}

尽管如此,如果重新连接尝试会引发超时,那么就会挽救你的脚本,因为你无法在没有连接的情况下进行更多的远程操作。