如何从另一个powershell窗口访问powershell会话?
我创建了一个 powershell 会话,
New-PSSession -ComputerName localhost
现在我可以访问上述会话
PS C:\> Get-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 localhost Opened Microsoft.PowerShell Available
PS C:\> Enter-PSSession -Id 1
,如果我打开另一个 powershell 窗口,那么我可以访问上面创建的会话吗? 我确实尝试过,但“Enter-PSSession -Id 1”对我不起作用。这有可能吗?
I have an powershell session created by
New-PSSession -ComputerName localhost
I'm able to access the above session by
PS C:\> Get-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 localhost Opened Microsoft.PowerShell Available
PS C:\> Enter-PSSession -Id 1
Now if I open another powershell window, then can I access the session created above ?
I did try but "Enter-PSSession -Id 1" did't work for me. Is this possible at all ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法从另一个实例连接到在一个实例中创建的会话,会话是隔离的并且仅对创建它们的主机可用。
You cannot connect to sessions created in one instance from another one, sessions are isolated and available only to the host that created them.
Enter-PSHostProcess cmdlet 连接并进入与本地进程的交互式会话。从 PowerShell 6.2 开始,非 Windows 平台支持此 cmdlet。
要获取其他会话,您可以使用 $PID 或 获取 PSHostProcessInfo。
然后您可以使用 Enter-PSHostProcess 连接到它。
请参阅 Enable-RunspaceDebug 和 < a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/debug-runspace" rel="nofollow noreferrer">Debug-Runspace 从您连接的会话调试运行空间。
The Enter-PSHostProcess cmdlet connects to and enters into an interactive session with a local process. Beginning in PowerShell 6.2, this cmdlet is supported on non-Windows platforms.
To get the other session(s), you can use $PID or Get-PSHostProcessInfo.
Then you can connect to it using Enter-PSHostProcess.
See Enable-RunspaceDebug and Debug-Runspace on debugging a Runspace from the session you connected to.