【问题标题】:New-PSSession does not work locallyNew-PSSession 在本地不起作用
【发布时间】:2015-05-25 13:40:36
【问题描述】:

我正在尝试使用New-PSSession 连接到本地主机。

我有

  • 使用配置的 WinRM

    winrm quickconfig
    
  • 启用 PS 远程处理

    Enable-PSRemoting
    
  • 添加了可信主机

    Set-Item WSMan:\localhost\Client\TrustedHosts * -Force
    
  • 防火墙的 8173 端口有入站规则。

winrm的输出:

PS C:\> winrm get winrm/config/listener?Address=*+Transport=HTTP
Listener
    Address = *
    Transport = HTTP
    Port = 8173
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    Listening on = 127.0.0.1

我正在尝试运行以下命令:

New-PSSession -ConnectionUri http://localhost:8173/WSMAN

但我收到此错误:

[localhost] Processing data from remote server failed with the following error message:
Error with error code 14 occurred while calling method WSManPluginReceiveResult. For
more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

编辑:

我看到的唯一额外的事情是网络连接到公共 $listenerport = "8173" winrmwinrm 创建 winrm/config/Listener?Address=*+Transport=HTTP "@{Port="$listenerport"}"

C:\>winrm get winrm/config
Config
    MaxEnvelopeSizekb = 1039440
    MaxTimeoutms = 60000
    MaxBatchItems = 32000
    MaxProviderRequests = 4294967295
    Client
        NetworkDelayms = 5000
        URLPrefix = wsman
        AllowUnencrypted = true
        Auth
            Basic = true
            Digest = true
            Kerberos = true
            Negotiate = true
            Certificate = true
            CredSSP = false
        DefaultPorts
            HTTP = 8173
            HTTPS = 5986
        TrustedHosts = *
    Service
        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GA;;;S-1-5-21-2458768215-3945602940-3262220185-1045)S:P(AU;FA;GA;;;WD)(AU;SA;GWGX;;;WD)
        MaxConcurrentOperations = 4294967295
        MaxConcurrentOperationsPerUser = 500
        EnumerationTimeoutms = 60000
        MaxConnections = 25
        MaxPacketRetrievalTimeSeconds = 120
        AllowUnencrypted = true
        Auth
            Basic = true
            Kerberos = false
            Negotiate = true
            Certificate = true
            CredSSP = false
            CbtHardeningLevel = Relaxed
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        IPv4Filter = *
        IPv6Filter = *
        EnableCompatibilityHttpListener = false
        EnableCompatibilityHttpsListener = false
        CertificateThumbprint
    Winrs
        AllowRemoteShellAccess = true
        IdleTimeout = 180000
        MaxConcurrentUsers = 5
        MaxShellRunTime = 2147483647
        MaxProcessesPerShell = 15
        MaxMemoryPerShellMB = 150
        MaxShellsPerUser = 5


PS C:\> Get-PSSessionConfiguration microsoft.powershell | fl *


xmlns            : http://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
Name             : Microsoft.PowerShell
Filename         : %windir%\system32\pwrshplugin.dll
SDKVersion       : 1
XmlRenderingType : text
lang             : en-US
PSVersion        : 2.0
ResourceUri      : http://schemas.microsoft.com/powershell/Microsoft.PowerShell
SupportsOptions  : true
ExactMatch       : true
Capability       : {Shell}
Permission       :

Administrators group have permission as I see in the window popup (Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI)

编辑 2:

【问题讨论】:

  • 默认端口是5985。你的8173winrm quickconfig 是如何设置的?让我印象深刻的一件事是您的 winrm get 输出缺少我的行:ListeningOn = 127.0.0.1, ::1(我的还包括服务器拥有的其他 IP)。
  • 使用 winrm create winrm/config/Listener?Address=*+Transport=HTTP 命令并在 8173 端口上创建了一个监听器。然后在 8173 端口上添加防火墙例外规则。是的,我的输出包含正在侦听。错过了。
  • powershell.com/cs/forums/t/11426.aspx的任何建议有帮助吗?
  • 您能否发布您用于创建自定义侦听器的确切命令?没有它,没有人可以尝试重现您的问题。
  • 您也可以发布您的客户端配置吗? winrm get winrm/config/client

标签: powershell winrm


【解决方案1】:

通过排除过程,我们可以排除防火墙问题,因为您只连接到环回地址 (127.0.0.1)。我们也可以排除看起来不错的 WinRM 配置。

错误信息表明与http://localhost:8173/WSMAN的TCP连接实际上是成功的,但是在建立PS会话时发生了错误。

这指向 Microsoft.PowerShell 会话配置。

您在查看时看到的权限似乎存在差异

Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI 

以及实际分配给 Microsoft.PowerShell 的权限。 的输出

Get-PSSessionConfiguration microsoft.powershell | fl *

应该列出“SecurityDescriptorSddl”和“Permission”属性。像这样:

Name                   : microsoft.powershell
Filename               : %windir%\system32\pwrshplugin.dll
SDKVersion             : 1
XmlRenderingType       : text
lang                   : en-US
PSVersion              : 2.0
ResourceUri            : http://schemas.microsoft.com/powershell/microsoft.powershell
SupportsOptions        : true
Capability             : {Shell}
xmlns                  : http://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
Uri                    : http://schemas.microsoft.com/powershell/microsoft.powershell
ExactMatch             : true
SecurityDescriptorSddl : O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
Permission             : BUILTIN\Administrators AccessAllowed

尝试删除并重新分配这些权限。

编辑:

根据您提供的信息,这不是主要问题。我还注意到您在 WinRM 服务设置中有一个非标准的“RootSDDL”。

RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;S-1-5-21-2458768215-3945602940-3262220185-1045)(AU;SA;GWGX;;;WD)

默认情况下应该是

RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GWGX;;;WD)

我在测试虚拟机上重新创建了这个,远程处理仍然有效。所以我又看了一下你的 WinRM 配置...

解决方案

你的问题是这一行

MaxEnvelopeSizekb = 1039440

通过设置此值,我可以复制您遇到的问题。我建议将其设置为更合理的值或默认值。

winrm set winrm/config '@{MaxEnvelopeSizekb="150"}'

会解决你的问题。

【讨论】:

  • 用权限的图片更新了问题
  • 执行了以下 PS> Unregister-PSSessionConfiguration microsoft.powershell PS> Enable-PSRemoting PS> Get-PSSessionConfiguration microsoft.powershell |最大*
【解决方案2】:

在我将计算机从 win 10 1607 升级到 1708 后,设置以下对我有用

更新将以下 reg 键更改为 1,并将其设置回 0 对我有用

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
FilterAdministratorToken=dword:0

【讨论】:

    【解决方案3】:

    在“严格”的 IPV4 环境中,我们也遇到了同样的问题。

    原因是:WinRM(和其他服务)似乎使用 IpV6-Loopback-Address,即使 ipv6 到处都被禁用。 (这没问题,除了 WinRM)

    因此,如果没有用于 IPV6 环回地址的 WinRM 侦听器 - 即使 WinRM 从远程主机工作,您也无法连接到本地主机。

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 1970-01-01
      • 2011-04-11
      • 2020-11-25
      • 2015-11-03
      • 1970-01-01
      • 2018-03-27
      • 2020-02-07
      • 2021-08-25
      相关资源
      最近更新 更多