powershell v2 远程处理 - 如何启用未加密的流量
-
16-09-2019 - |
题
我正在编写一个 powershell v2 脚本,我想在远程服务器上运行它。当我运行它时,我收到错误:
连接到远程服务器的失败,以下错误消息失败:这 WinRM 客户端无法处理 请求。未加密的流量是 当前在客户端中禁用 配置。更改客户端 configurati on 并尝试请求 再。有关更多信息,请参阅 about_ Remote_Troubleshooting帮助 主题。
我查看了有关_Remote_Troubleshooting 的在线帮助,但它没有指出如何启用未加密的流量。下面是我正在使用的导致我出现问题的脚本。
笔记:我已经在远程计算机上运行 Enable-PSRemoting 以允许其接受传入请求。
我尝试使用会话选项变量,但它似乎没有任何区别。
$key = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds"
Set-ItemProperty $key ConsolePrompting True
$tvar = "password"
$password = ConvertTo-SecureString -string $tvar -asPlainText –force
$username="domain\username"
$mySessionOption = New-PSSessionOption -NoEncryption
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
invoke-command -filepath C:\scripts\RemoteScript.ps1 -sessionoption $mySessionOption -authentication digest -credential $credential -computername RemoteServer
如何启用未加密的流量?
解决方案
AllowEncrypted 在客户端通过 WSMAN 定义:驾驶。您必须将 powershell.exe(或 powershell_ise.exe)作为提升的进程运行。
ps> cd WSMan:\localhost\Client
ps> dir
Name Value
---- -----
NetworkDelayms 5000
URLPrefix wsman
AllowUnencrypted false
Auth
DefaultPorts
TrustedHosts
您可以像这样更改它(更改到上面的目录后):
ps> set-item .\allowunencrypted $true
希望这可以帮助,
- 奥辛
其他提示
您可能会需要设置AllowUnencrypted配置设置在客户端和服务两者。服务设置具有使用以下在远程服务器将被改变:
set-item -force WSMan:\localhost\Service\AllowUnencrypted $true
和不要忘记也开启摘要授权:
set-item -force WSMan:\localhost\Service\Auth\Digest $true
这为我工作:
enable-wsmancredssp –role server
不隶属于 StackOverflow