2017-04-19 136 views
0

我有一個腳本,打開本地主機的遠程會話。 我需要這個從一個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

回答

0

問題是有人篡改了防火牆...感謝幫助的人!

基本上防火牆GPO阻止遠程管理

+0

歡迎來到Docschnitzel網站,幫助人們進一步嘗試併爲您的原始問題標記正確的答案。我發現你已經設法說@Moewalds的回答是正確的,但你寫了一條評論說它不起作用,然後你有自己的其他答案說明這是一個防火牆問題。你做了什麼來解決你的問題?一旦你解釋說你可以將自己的答案標記爲正確答案。 –

+0

非常感謝您的支持,我清理了自己的答案,並將它作爲答案在幾個小時內(當網站允許我標記它時) – Docschnitzel

0

檢查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