1

To elaborate, I am creating a remote power shell session to localhost. Essentially, I am running the below command from my first power shell session(1).

$s = New-PSSession;

Now, I opened another power shell session(2) and I want to connect to the remote session created in the power session(1).

Is this possible?

I see that the remote power shell sessions created in (1) are not visible in (2). Is there a way to access those remote sessions across different power shell sessions.

0

1 Answer 1

2

Fortunately this feature has been added to PowerShell 3 for the first time. By using the parameter -ComputerName in Get-PSSession and opening the PS sessions with the same credentials, you can get all the sessions that have been created on this remote machine by your credentials. Try to type this line in the 1st session

New-PSSession -ComputerName LocalHost

Then this line in the 2nd session

Get-PSSession -ComputerName LocalHost

I have found the following link is very useful for this topic:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pssession_details?view=powershell-6

Sign up to request clarification or add additional context in comments.

3 Comments

One thing which I see is, even when I am creating remote session in powershell 1 and trying to login in powershell 2, it always says that PSSession is in a disconnected state and not available for connection. Powershell 2 is just listing the session details, but not allowing to enter the session. Is there any work around for this?
you must disconnect the PSSession from the first session so you can connect from the second session. use the two commands Disconnect-PSSession and Connect-PSSession to do that, then use Enter-PSSession to initiate the session. hope that work for you.
Thank you @BahyGHassan. Moreover, I got an awesome blog which points out all these things to the point. 4sysops.com/archives/powershell-disconnected-remote-sessions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.