5

For remote work on a Linux server, I can ssh and then tmux to resume my work (including stdout/stderr).

How can I get the same experience on Windows server using Powershell? I have done some basic reading on Enter-PSSession but that feels like ssh without tmux.

Fabian
  • 990
  • 3
  • 11
  • 24

1 Answers1

8

When you use Enter-PSSession and exit with Exit-PSSession, The Session is Permanently deleted and you can't resume it.

However, You can Create a Remote Session like this:

$session = New-PSSession -ComputerName $ComputerName

And Then Connect into it

Enter-PSSession $session

This way You Can disconnect (but the session will remain connected)

Exit-PSSession

And Reconnect again (and come back to the same state)

Enter-PSSession $session

As long as $session variable is available the session remains open and all your work remain in the same state

To Disconnect the Session:

Disconnect-PSSession $session

To remove the Session:

Remove-PSSession $session
Avshalom
  • 8,657
  • 1
  • 25
  • 43
  • Thanks but I have a few follow-up questions. (1) If I want to multi-task, do I need to create multiple PSSessions? (2) If I exit a session (e.g. due to lost connection or closed laptop) while running a program that prints to stdout, what would I see when I re-enter that session? – Fabian Sep 09 '15 at 05:23
  • (1) yes create multiple PSSesions, (2) as long as your powershell session open it remains open, if you want to save your session commands, this might help as well, http://blogs.msdn.com/b/powershell/archive/2009/12/29/saving-remote-session-to-your-local-disk.aspx – Avshalom Sep 09 '15 at 08:10