Are manually made PS sessions destroyed when the console is closed?

This is a noobish question but I’m not able to find an answer.

Suppose you create a new PS session with New-PSSession command and then you close the PS console without running Remove-PSSession.

Will closing the console remove the session that you manually made?

edit:

If you can point to me documentation which confirms PSSession is removed automatically that would a plus.

You could try it yourself. Create a new pssession, connect to it, create some objects or variables, close the console, open a new console, use Connect-PSSession to connect to the remote computer and try if the objects or variables you created before are still there. :wink:

Sorry but I don’t think this would be a genuine test for all the scenarios that I face, for ex. Get-PSSession works only for session created in current PS session.

Thus ie. using Connect-PSSession with Name parameter will not work since the name of a session is local to console session where the session was made, this doesn’t prove nor disprove whether the session itself is still alive.

I’ve read on New-PSSession page:

The New-PSSession cmdlet creates a PowerShell session (PSSession ) on a local or remote computer. When you create a PSSession , PowerShell establishes a persistent connection to the remote computer.

But “persistent session” does not mean that the session is imortal, it rather means that you don’t need to specify -ComputerName parameter and simialar which creates a temporary session.

Then also I suppose it depends on whether the session is to localhost or remote host.

That’s a lot of testing for me to do and in the end I will not be 100% sure.
I seek a concrete answer which applies to all possible scenarios, ex. local vs remote session, what if remote computer shuts down? what happens with the session then if it was alive?

There are so many variables to test.

So you may try with the parameter -ComputerName. :wink: … if we’re talking about remote sessions.

Hmmm … I understood that you only wanted to know if a session persists when the console you created it is closed. That should be quiet straight forward in my opinion.

Wow … you may ask the PowerShell team directly … I pass for that requirement.

I did some research and learned that session exists for as long as it is either removed with Remove-PSSession or until is times out.

By default a session does not time out and lives for as long as computer is up, but one can control the timeout of a session with New-PSSessionOption

Reference:

The PSSession remains available until you delete it or it times out.

-IdleTimeout

Determines how long the session stays open if the remote computer does not receive any communication from the local computer. This includes the heartbeat signal. When the interval expires, the session closes.

The idle time-out value is of significant importance if you intend to disconnect and reconnect to a session. You can reconnect only if the session has not timed out.

The following article was also useful:

Sure I could, but I don’t practice creating issue questions for every problem I enounter unless there is absolutely no way to research it or getting help from forums or Q\A.

Thank you for your reply though!

Cool. :+1:t4: There you have your answer. :man_shrugging:t4: And thanks for sharing. :love_you_gesture:t4: