I can start 5 new PS sessions on a remote server and see them all by running Get-PSSession
PS C:\> New-PSSession -ComputerName MyServerName
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 MyServerName Opened Microsoft.PowerShell Available
[repeat 4 more times]
As expected, when I try to open a 6th session, I get the error saying that's a no-no (due to PoswerShells default limit of 5 concurrent remote PSSessions). But running Get-Session shows all 5 sessions so all is working as it should be so far:
PS C:\> New-PSSession -ComputerName MyServerName
New-PSSession : [......maximum number of 5 concurrent shells]
PS C:\> Get-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 MyServerName Opened Microsoft.PowerShell Available
2 Session2 MyServerName Opened Microsoft.PowerShell Available
3 Session3 MyServerName Opened Microsoft.PowerShell Available
4 Session4 MyServerName Opened Microsoft.PowerShell Available
5 Session5 MyServerName Opened Microsoft.PowerShell Available
However, when I close that console and open a new one, running Get-PSSession (with or without the '-ComputerName' parameter defined) shows no open sessions at all.
PS C:\> Get-PSSession
PS C:\>
I know those sessions are still open because when I try to open a new one in my new console I get the same error regarding more than 5 concurrent sessions:
PS C:\> New-PSSession -ComputerName MyServerName
New-PSSession : [......maximum number of 5 concurrent shells]
According to 'Get-PSSession Get-Help -full' running 'Get-PSSession -ComputerName MyServerName should get all remote PS sessions on a particular server regardless of what session or computer they were started from (at least the way I understand it):
"The command returns all of the sessions on [the remote server], even if they were created in different sessions or on different computers."
So, is there a way to find and/or remove any open PS sessions on a remote server -- without having to do it all from one console session?