I'm trying to figure out how to retrieve all existing remote PowerShell sessions (user-managed) between a client and an Exchange 2013 server.
Running Get-PSSession only returns remote sessions created within the current PowerShell session (system-managed). I need to do this from within adifferent PowerShell session, possibly even from a different computer from where those remote sessions were established.
Documentation for Get-PSSession states that this should be possible starting with PS 3.0 since user-managed sessions are now stored locally on the remote server (in my case, the Exchange 2013 server) and can later be retrieved from any system-managed session by using Get-PSSession with either the ComputerName or ConnectionUri parameter sets.
Here's how those remote sessions are created:
PS $> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<exchange_server>/powershell/ -Credential $credential -Authentication Basic -AllowRedirection
PS $> Import-PSSession $Session
And how I try to retrieve those session afterward:
PS $> Get-PSSession -ComputerName <exchange_server> -ApplicationName powershell -Authentication Basic -Credential $credential -UseSSL -Port 443
PS $> Get-PSSession -ConnectionUri https://<exchange_server>/powershell/ -AllowRedirection -Authentication Basic -Credential $credential
Both methods yield no results (nor errors), while running Get-PSSession (without any parameters) within the same user-managed session would successfully return the session.
The only explanation I could think of right now is that somehow, WinRM on the Exchange server is not running PS 3.0 even though:
$PSVersionTable.PSVersion returns 3 0 -1 -1
winrm id returns ProductVersion = OS: 6.2.9200 SP: 0.0Stack: 3.0
But when I attempt to disconnect a remote session with this Exchange server using Disconnect-PSSession, I get the following error message:
Disconnect-PSSession : Disconnect-PSSession operation failed for runspace Id = XXXXX
for the following reason: The disconnection operation is not supported on the remote computer. To support
disconnecting, the remote computer must be running Windows PowerShell 3.0 or a later version of Windows PowerShell.
So I guess I have a couple questions:
- Are remote PSSession even supposed to be maintained onan Exchange 2013 server?
- If so, is it possible to retrieve them from a different session using GET-PSSession?
- Which version of PS 3.0 is used by WinRM on an Exchange 2013 server?
thanks