I am trying receive the status of all TransportAgents from an remote Exchange Server through Windows Powershell.
I sporadically receive an error, that the The session state is Broken
. Once it is broken I need to create a new Session
Below a list of the commands I am using (in proper order)
# 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>
When I repeat the command Invoke-Command $Session {Get-TransportAgent}
the following error occured sporadically:
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
UPDATE
After adding the IdleTimeout in SessionOption I'm receving the below error followed by 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>
Question: Why does the error occurs and how to solve this?