3

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
  • Get-PSSession return what ? – yagmoth555 Apr 04 '17 at 20:20
  • Hello @yagmoth555 I added the details you asked for. – Alexander Sinno Apr 04 '17 at 20:29
  • It's strange that the output show Opened and not Disconnected, is it an output when the user closed the windows without using Exit-PSSession ? – yagmoth555 Apr 04 '17 at 20:42
  • Theoretically setting WSMAN idle timeouts would control all WSMAN based sessions, or you could adjust the TransportOptions on the Microsoft.PowerShell endpoint... But it isn't working on my box like I expected. You can try. See `Set-PSSessionConfiguration Microsoft.PowerShell -TransportOption` and `New-Transportoption -IdleTimeoutSec`. You can see current endpoint configuration with `Get-PSSessionConfiguration Microsoft.PowerShell | fl *` – Matthew Wetmore Apr 05 '17 at 04:06
  • @yagmoth555 I am having the user import the modules. I'll edit and show you above for clarity. – Alexander Sinno Apr 05 '17 at 15:08
  • @MatthewWetmore It doesn't seem to be working out for me either. I just don't understand why the connection doesn't terminate when the user closes their PowerShell session. It would be interesting to know if there is a setting for this. – Alexander Sinno Apr 05 '17 at 15:09
  • Does not repro for me on Server 2016. The TCP connections are closed immediately when I close the Powershell window on the remote host. So it might be a bug that was patched in more recent versions. – Ryan Ries Apr 09 '17 at 15:15
  • I didn't get explicitly check connections, I just saw my remote session still was connectable, and if I left a entered possession in a console idle, expected it to be broken when I returned. – Matthew Wetmore Apr 09 '17 at 22:16

0 Answers0