Summary:
After running netstat, I noticed that my local device has several established connections to the remote server using port 5985 as seen below:
PS > netstat
Active Connections
Proto Local Address Foreign Address State
TCP x.x.x.x:3389 10.11.17.12:50603 ESTABLISHED
TCP x.x.x.x:5985 device:50581 ESTABLISHED
TCP x.x.x.x:5985 172.16.0.54:64858 TIME_WAIT
TCP x.x.x.x:5985 172.16.0.54:64859 ESTABLISHED
TCP x.x.x.x:5985 172.16.0.54:64860 ESTABLISHED
TCP x.x.x.x:5985 172.16.0.54:64861 ESTABLISHED
TCP x.x.x.x:5985 172.16.0.54:64862 ESTABLISHED
TCP x.x.x.x:5985 172.16.0.54:64863 ESTABLISHED
My device would be 172.16.0.54. However, I only have a single powershell session open on my local device.
Question:
Is there a way to terminate the open sessions once the user closes their shell on the local machine? If not, how can I regulate these connections? I would prefer to automatically close the session once the user exits their local shell, most users will not use 'Exit-PSSession.'
PS-Session Results:
PS > Get-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 ServerA Opened Microsoft.PowerShell Available
How I am importing modules to user sessions:
Invoke-command -ScriptBlock { Import-Module -Name 'Module A','Module B','Module C,'Module D','Module E' } -Session $ServerA
Import-PSSession -Module ''Module A','Module B','Module C,'Module D','Module E' -Session $ServerA -AllowClobber