【问题标题】:Cannot do local remoting无法进行本地远程处理
【发布时间】:2017-10-15 22:54:44
【问题描述】:

我可以在网络上的另一台机器上使用Invoke-Command。 我已经以管理员身份运行Enable-PSRemoting

  • PSVersion 5.0.10586.117
  • Windows 7 专业版 SP1

我错过了什么?

PS C:\Windows\system32> winrm 快速配置 WinRM 服务已经在这台机器上运行。 WinRM 已设置为在此计算机上进行远程管理。 PS C:\Windows\system32> Invoke-Command -ComputerName localhost -ScriptBlock { dir } [localhost] 连接到远程服务器 localhost 失败,出现以下错误 message :客户端无法连接到请求中指定的目的地。 验证目标上的服务是否正在运行并且正在接受请求。 查阅在 WS-Management 服务上运行的日志和文档 目的地,最常见的是 IIS 或 WinRM。如果目标是 WinRM 服务, 在目标上运行以下命令以分析和配置 WinRM 服务:“winrm 快速配置”。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 + CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException + FullyQualifiedErrorId:无法连接,PSSessionStateBroken

DisableStrictNameChecking 设置为一 (1) 后,出现相同的错误消息。

BackConnectionHostNames设置为“localhost”和“ALFRED”后,出现同样的错误信息。

将 DisableLoopbackCheck 设置为一 (1) 后,会出现以下消息。

PS C:\Windows\system32> winrm quickconfig
WinRM service is already running on this machine.
WSManFault
    Message
        ProviderFault
            WSManFault
                Message = WinRM firewall exception will not work since one of the network connection types on this ma
chine is set to Public. Change the network connection type to either Domain or Private and try again.

Error number:  -2144108183 0x80338169
WinRM firewall exception will not work since one of the network connection 
types on this machine is set to Public. Ch
ange the network connection type to either Domain or Private and try again.

我似乎没有更改网络类型的权限。我在企业 VPN 上。 company.com 网络是Domain network,但另一个网络是Public network。如果我不能改变它,那么我似乎无法从这里到达那里。

【问题讨论】:

    标签: powershell powershell-remoting


    【解决方案1】:

    这是一种称为“NTLM 环回检查”的安全功能。您可以在MS KB articleMarc Lognoul's blog 查看更多详细信息。简而言之,Kerberos 不能与远程主机名的“localhost”或“127.0.0.1”或“[::1]”一起使用。身份验证失败返回 NTLM,并且它具有与环回 IP 相关的漏洞。

    解决方案是禁用注册表中的环回检查,如该 MS 页面上的方法 2 所述。

    【讨论】:

    • 我已将 DisableStrictNameChecking 设置为一 (1),如所述,但仍然失败。还有什么我需要做的吗?典型的公司环境是否会“锁定”其他一些事情来阻止它发挥作用?
    • 对不起,我的错误。您应该禁用 LoopBackCheck,Microsoft 修复的第二部分。即使不禁用严格的名称检查,它甚至也可以工作。我将编辑我的答案。
    【解决方案2】:

    删除 WinRM 旧监听器。

    winrm 删除 winrm/config/Listener?Address=*+Transport=HTTPS

    首先需要创建自签名证书并获取其指纹

    1.New-SelfSignedCertificate -DnsName "" -CertStoreLocation Cert:\LocalMachine\My

    将指纹复制到剪贴板并运行以下命令。此命令将在 WinRM 中注册 HTTPS 侦听器

    2.winrm 创建 winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=""; CertificateThumbprint=""}

    添加新的防火墙规则

    port=5986
    netsh advfirewall firewall add rule name="Windows Remote Management (HTTPS-In)" dir=in action=allow protocol=TCP localport=$port
    

    【讨论】:

      【解决方案3】:
      1. 检查您的网络连接是否设置为public
      2. 在 localhost 上设置远程处理

      (1) 以管理员权限启动新的 powershell 窗口(以管理员身份运行)
      (2) 使用以下命令检索您的本地主机名称:hostname
      (3) 使用如下命令将该主机名加入受信任服务器列表:
      Set-Item WSMan:\localhost\Client\TrustedHosts -Value "<Your hostname from (2) above>"

      1. 激活远程处理:
        Winrm qc
        Enable-PSRemoting

      2. 测试:
        Invoke-Command -ComputerName localhost -ScriptBlock {hostname}

      注意事项:

      1. 远程处理仅适用于提升的 Powershell
      2. 从 CMD 提升:
        powershell -Command "start PowerShell -Verb RunAs"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-10
        • 2015-11-08
        • 1970-01-01
        • 2014-11-25
        相关资源
        最近更新 更多