powershell v2 remoting - 如何启用未加密的流量

Pet*_*lke 31 powershell powershell-2.0

我正在编写一个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
Run Code Online (Sandbox Code Playgroud)

如何启用未加密的流量?

x0n*_*x0n 45

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
Run Code Online (Sandbox Code Playgroud)

您可以像这样更改它(在更改到上面的目录后):

ps> set-item.\ allowunencrypted $ true

希望这可以帮助,

  • [287]莪


小智 12

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

set-item -force WSMan:\localhost\Service\AllowUnencrypted $true
Run Code Online (Sandbox Code Playgroud)

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

set-item -force WSMan:\localhost\Service\Auth\Digest $true
Run Code Online (Sandbox Code Playgroud)

  • 为什么需要启用摘要授权? (2认同)
  • 哦,傻我!当然,这是允许系统消化新设置. (2认同)
  • 我很欣赏你的 IT 幽默@x0n (2认同)