32

我正在编写一个我想在远程服务器上运行的 powershell v2 脚本。当我运行它时,我收到错误:

连接到远程服务器失败并显示以下错误消息:WinRM 客户端无法处理请求。当前在客户端配置中禁用了未加密的流量。更改客户端配置并再次尝试请求。有关详细信息,请参阅 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

如何启用未加密的流量?

4

5 回答 5

49

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> 设置项 .\allowunencrypted $true

希望这可以帮助,

  • 奥辛
于 2009-09-24T19:28:59.693 回答
12

您可能需要在客户端和服务中设置 AllowUnencrypted 配置设置。必须使用以下命令在远程服务器中更改服务设置:

set-item -force WSMan:\localhost\Service\AllowUnencrypted $true

并且不要忘记启用摘要授权:

set-item -force WSMan:\localhost\Service\Auth\Digest $true
于 2009-11-03T22:31:46.743 回答
3

您可以使用以下命令在客户端上允许未加密的流量(在客户端上执行):

winrm set winrm/config/client '@{AllowUnencrypted="true"}'

要验证,您可以使用以下命令获取整个配置(客户端和服务):

winrm get winrm/config

请注意,每台机器都有两个配置(一个作为客户端,一个作为服务器)。要允许服务器上的未加密流量,请在服务器上执行以下命令:

winrm set winrm/config/service '@{AllowUnencrypted="true"}'
于 2020-05-05T11:53:35.413 回答
1

这对我有用:

enable-wsmancredssp –role server
于 2017-08-17T10:33:23.557 回答
0

如果参数AllowUnencryptedTraffic在 下GPO,可以通过registrar设置:

$RegPath = 'HKLM:\Software\Policies\Microsoft\Windows\WinRM\Client'
$RegUnencryptedTraffic = 'AllowUnencryptedTraffic'
$RegValue = '1'
Set-ItemProperty -Path $RegPath -Name $RegUnencryptedTraffic -Value $RegValue
于 2021-10-04T11:36:42.020 回答