powershell - 如何从本地使用 powershell 连接到远程服务器。Enter-PSSession 不工作
问题描述
我正在尝试使用本地 powershell 会话连接到远程计算机。
为此,我尝试使用本地 powershellEnter-PSSession
或New-PSSession
命令作为:
$session = New-PSSession -ConnectionUri 'http://testserverUri.dom/PowerShell'
但是我总是在异常之后得到。
New-PSSession : [testserveruri.dom] Connecting to remote server apdv0710.forest7.dom failed with the following
error message : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was
not available. This is usually returned by a HTTP server that does not support the WS-Management protocol. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = New-PSSession -ConnectionUri 'http://testserverUri.dom/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
gTransportException
+ FullyQualifiedErrorId : URLNotAvailable,PSSessionOpenFailed
我还使用了其他变体:
Enter-PSSession -Authentication Kerberos -ConnectionUri 'http://testserveruri.dom/PowerShell' -Cred $credential
Enter-PSSession : Connecting to remote server apdv0710.forest7.dom failed with the following error message : The WinRM
client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is
usually returned by a HTTP server that does not support the WS-Management protocol. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = Enter-PSSession -Authentication Kerberos -ConnectionUri 'h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (http://testserveruri.dom/PowerShell:Uri) [Enter-PSSession], PSRemot
ingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
在大多数情况下,我得到了第一个例外。
当我使用 C# 打开运行空间并为 WSManConnectionInfo 对象提供远程服务器 powerSell url 时,也会发生同样的异常。
我已经对 winrm 命令进行了各种处理,但这并不能真正解决问题。如何摆脱这个问题?
解决方案
通过仅提供计算机名称、Kerberos 作为身份验证机制以及包含用户名和密码的凭据对象,这对我有用。
New-PSSession -Authentication Kerberos -Computer 'apdv004s' -Cred $credential
相同的用法Enter-PSSession
推荐阅读
- reactjs - React:加载图像之前的图像大小问题
- java - Viewpager2打开所选页面(来自cardview)没有片段
- r - 基于类似称为列中的值的新列的属性值
- javascript - 如何从函数范围访问数组
- php - 目标类 [App\Http\Controllers\Admin\Category\CategoryController] 不存在
- python - Pandas 数据框搜索和修改邮政编码的前导零
- google-ads-api - Adwords API 中的报告不再出现在 Ads API 中
- apache - 将任何子域 URL 上的任何链接重定向到另一个域
- android - android启动活动中奇怪的白线
- rest - 通过多个文档 ID 查询 Firestore Rest API