powershell Invoke-Command中再使用New-PsSession嵌套远程问题


PowerShell交流中心分类: 远程管理powershell Invoke-Command中再使用New-PsSession嵌套远程问题
0
tengoshop asked 6年 ago

powershell Invoke-Command中再使用New-PsSession嵌套远程问题如何解决?
$session = New-PsSession $ip -Credential $cred
Invoke-Command -Session $session {
//…
$sessionNext = New-PsSession $ip2 -Credential $cred2
//出现错误
//New-PsSession : [172.16.2.6] 连接到远程服务器 172.16.2.6 失败,并显示以下错误消
//息: WinRM 无法处理该请求。使用 Negotiate 身份验证时发生错误代码为 0x8009030d 的
//以下错误: 指定的登录会话不存在。可能已被终止。
}

3 Answers
1
Best Answer
kelin219 answered 6年 ago

可参考微软官方文档:https://docs.microsoft.com/zh-cn/powershell/scripting/setup/ps-remoting-second-hop?view=powershell-5.1#just-enough-administration-jea
里面提到的【使用 RunAs 的 PSSessionConfiguration】即可解决这个问题!

Mooser Lee 管理员 replied 6年 ago

感谢分享

0
robo answered 6年 ago

您好 ,请教一下。我在使用这个Invoke-Command 在远程服务器上执行命令时,无法连接,我的远程服务器远程端口号不是默认的。
PS C:\Users\Administrator> Invoke-Command -ScriptBlock {dir C:\} -Credential $cred -ComputerName $computerName
[192.168.1.2] 连接到远程服务器 192.168.1.2 失败,并显示以下错误消息: WinRM 无法完成该操作。 请验证指定的计算机名称有效,可以通过网络访问该计算机,以及启用
了 WinRM 服务的防火墙例外并允许从此计算机中进行访问。 默认情况下,公用配置文件的 WinRM 防火墙例外仅限访问同一本地子网中的远程计算机。 有关详细信息,请参阅 about_R
emote_Troubleshooting 帮助主题。
+ CategoryInfo : OpenError: (192.168.1.2:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
PS C:\Users\Administrator> Invoke-Command -ScriptBlock {dir C:\} -Credential $cred -ComputerName $computerName -Port 11111
[192.168.1.2] 连接到远程服务器 192.168.1.2失败,并显示以下错误消息: WinRM 无法完成该操作。 请验证指定的计算机名称有效,可以通过网络访问该计算机,以及启用
了 WinRM 服务的防火墙例外并允许从此计算机中进行访问。 默认情况下,公用配置文件的 WinRM 防火墙例外仅限访问同一本地子网中的远程计算机。 有关详细信息,请参阅 about_R
emote_Troubleshooting 帮助主题。
+ CategoryInfo : OpenError: (192.168.1.2:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken

robo replied 6年 ago

我 明白了。