Close Your PowerShell Sessions! – Office 365

If you have ever received the error message below or a similar one then you are not closing your PowerShell sessions properly (or at all!).

[serverName] Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. This user is allowed a maximum number of 3 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException + FullyQualifiedErrorId : PSSessionOpenFailed

The way to close your PowerShell sessions is to use the Remove-PSSession command once you have finished with your session.

We use the following to create the session:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange-ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection

We now end the above session by entering:

Remove-PSSession $Session