新的PSSession本地主机失败

问题描述:

我有一个脚本,打开本地主机的远程会话。 我需要这个从一个logonscript内的某些设备上安装NuGet。新的PSSession本地主机失败

$Username = "Admin" 
$Password = ConvertTo-SecureString ‘adminPW’ -AsPlainText -Force 
$adminCredential = New-Object System.Management.Automation.PSCredential $Username, $Password 
$Session = New-PSSession -Credential $adminCredential 
Invoke-Command -Session $Session -ScriptBlock {Install-PackageProvider -Name NuGet -Verbose -MinimumVersion 2.8.5.201 -Force} 

每次我尝试运行此我得到以下错误:

 
New-PSSession : [localhost] Connecting to remote server localhost failed with the following error message : The client cannot connect to the destination 
specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the 
WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the 
destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic. 
At C:\Users\Mike Holtackers\OneDrive - Foreign Trade Association\Scripts\OutlookSig\getAADconnectionOK.ps1:5 char:12 
+ $Session = New-PSSession -ConnectionUri $ConnectionURI -Credential $a ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException 
    + FullyQualifiedErrorId : CannotConnect,PSSessionOpenFailed 

运行winrm quickconfig不会改变任何东西......

以下是winrm get winrm/config

 
PS WSMan:\localhost\Listener\Listener_1084132640> winrm get winrm/config 
Config 
    MaxEnvelopeSizekb = 500 
    MaxTimeoutms = 60000 
    MaxBatchItems = 32000 
    MaxProviderRequests = 4294967295 
    Client 
     NetworkDelayms = 5000 
     URLPrefix = wsman 
     AllowUnencrypted = false 
     Auth 
      Basic = true 
      Digest = true 
      Kerberos = true 
      Negotiate = true 
      Certificate = true 
      CredSSP = false 
     DefaultPorts 
      HTTP = 5985 
      HTTPS = 5986 
     TrustedHosts = * 
    Service 
     RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) 
     MaxConcurrentOperations = 4294967295 
     MaxConcurrentOperationsPerUser = 1500 
     EnumerationTimeoutms = 240000 
     MaxConnections = 300 
     MaxPacketRetrievalTimeSeconds = 120 
     AllowUnencrypted = false 
     Auth 
      Basic = false 
      Kerberos = true 
      Negotiate = true 
      Certificate = false 
      CredSSP = false 
      CbtHardeningLevel = Relaxed 
     DefaultPorts 
      HTTP = 5985 
      HTTPS = 5986 
     IPv4Filter = 194.168.254.1-194.168.254.256 [Source="GPO"] 
     IPv6Filter [Source="GPO"] 
     EnableCompatibilityHttpListener = false 
     EnableCompatibilityHttpsListener = false 
     CertificateThumbprint 
     AllowRemoteAccess = true [Source="GPO"] 
    Winrs 
     AllowRemoteShellAccess = true 
     IdleTimeout = 7200000 
     MaxConcurrentUsers = 2147483647 
     MaxShellRunTime = 2147483647 
     MaxProcessesPerShell = 2147483647 
     MaxMemoryPerShellMB = 2147483647 
     MaxShellsPerUser = 2147483647 
输出
+1

您是否在计算机上运行了'Enable-PSRemoting'? –

+0

是的,我有。试过它再次是陛下,但仍然产生相同的结果 – Docschnitzel

+1

你有没有更新您的WinRM TrustedHosts,让您连接到本地主机? – TessellatingHeckler

问题是有人篡改了防火墙...感谢帮助的人!

基本上防火墙GPO阻止远程管理

+0

欢迎来到Docschnitzel网站,帮助人们进一步尝试并为您的原始问题标记正确的答案。我发现你已经设法说@Moewalds的回答是正确的,但你写了一条评论说它不起作用,然后你有自己的其他答案说明这是一个防火墙问题。你做了什么来解决你的问题?一旦你解释说你可以将自己的答案标记为正确答案。 –

+0

非常感谢您的支持,我清理了自己的答案,并将它作为答案在几个小时内(当网站允许我标记它时) – Docschnitzel

检查winrm服务是否正在运行本地主机:

PS C:\> Get-Service winrm | ft -AutoSize 

Status Name DisplayName        
------ ---- -----------        
Running winrm Windows Remote Management (WS-Management) 

否则PS远程将无法正常工作,虽然你已经通过WinRM的配置,并通过Enable-PSRemoting启用PS远程处理。

+0

它已经在运行,谢谢:) 所以我仍然必须深入挖掘恐怕。 – Docschnitzel