title: PowerShell remote connection problems
body: <p>I’m trying to implement PowerShell remoting (for PowerShell script execution on a remote server).
  My remote server is running Windows Server 2008 and PowerShell v2.</p>
  
  <p>From an elevated permission PS console, I have executed the following cmdlet:</p>
  
  <pre><code>Enable-PSRemoting
  </code></pre>
  
  <p>Returned to console:</p>
  
  <blockquote>
    <p>WinRM already is set up to receive requests on this machine.</p>
    
    <p>WinRM already is set up for remote management on this machine.</p>
  </blockquote>
  
  <p>From an elevated PowerShell session on the client machine, I executed the following cmdlet:</p>
  
  <pre><code>Enter-PSSession –ComputerName [remote_server_name]
  </code></pre>
  
  <p>This time, returned to console:</p>
  
  <blockquote>
    <p>Enter-PSSession : Connecting to remote server [remote_server_name] 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.</p>
    
    <p>At line:1 char:1</p>
    
    <p>+ Enter_PSSession –ComputerName [remote_server_name]</p>
    
    <p>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
    
    <p>+ CategoryInfo     : Invalid/argument: ([remote_server_name]:string) [Enter-PSSession], PSRemotingTransportException</p>
    
    <p>+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed</p>
  </blockquote>
  
  <p>I executed the “winrm quickconfig” as per the error message suggestion. Once again, returned to console:</p>
  
  <blockquote>
    <p>WinRM already is set up to receive requests on this machine.</p>
    
    <p>WinRM already is set up for remote management on this machine.</p>
  </blockquote>
  
  <p>Retrying</p>
  
  <pre><code>Enter-PSSession –ComputerName [remote_server_name]
  </code></pre>
  
  <p>from the client machine retrurns the same error.</p>
  
  <p>I double checked that the WinRM service is running on the remote server.
  The Windows Remote Management (HTTP-In) firewall rule is configured for TCP protocol, local port 5985 and all remote ports.</p>
  
  <p>Even when I execute</p>
  
  <pre><code>Get-Service WinRM –ComputerName [remote_server_name]
  </code></pre>
  
  <p>from the client machine, we see returned to console, confirming that the WinRM service is indeed running on the remote server:</p>
  
  <blockquote>
    <p>Status        Name            DisplayName</p>
    
    <p>------        ----            ----------- </p>
    
    <p>Running   WinRM           Windows Remote Management (WS-Manag…</p>
  </blockquote>
  
  <p>Execution of the following command on the remote machine</p>
  
  <pre><code>WinRM Enumerate WinRM/Config/Listener
  </code></pre>
  
  <p>returns to console, demonstrating the correct port is open:</p>
  
  <blockquote>
    <p>Listener [Source=”GPO”]</p>
    
    <p>Address = *</p>
    
    <p>Port = 5985</p>
    
    <p>Hostname Enabled = true</p>
    
    <p>URLPrefix = wsman</p>
    
    <p>CertificateThumbprint ListeningOn = null</p>
  </blockquote>
  
  <p>But, execution of </p>
  
  <pre><code>$remoteServer = [test_server_name]
  $port = 5985
  $connection = New-Object System.Net.Sockets.TcpClient($remoteServer, $port)
  if ($connection.Connected) {
      Write-Host "Success"
  }
  else {
      Write-Host "Failed"
  }
  </code></pre>
  
  <p>returns the following error message:</p>
  
  <blockquote>
    <p>New-Object : Exception calling ".ctor" with "2" argument(s): "No connection could be made because the target machine actively refused it [remote_server_ipaddress]:5985"</p>
    
    <p>At line:4 char:15</p>
    
    <p>+ ... onnection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port ...</p>
    
    <p>+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
    
    <p>+ CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException</p>
    
    <p>+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand</p>
  </blockquote>
  
  <p>I have another remote server, running Windows Server 2012 R2 with PowerShell v4. I have enabled PS remoting on this box without issue and can remotely execute PS scripts from the same client.</p>
  
  <p>So, what am I missing? Is there a possibility that there is a compatibility problem between PowerShell versions?</p>
  
  <p>My client PC is running PowerShell 5, my correctly functioning remote server is running PowerShell 4, my failing remote server is running PowerShell 2.</p>
  
  <p>Insights, guidance, advice very welcome. Thanks for looking.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've since updated the .Net Framework on bothe test VMs to .Net 4.7.2 and installed PowerShell 4 on the affected VM (same as the correctly functioning box).</p>
  
  <p>Whilst comparing WinRM related registry entries between my working VM and the affected machine, I found the key:</p>
  
  <blockquote>
    <p>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service</p>
  </blockquote>
  
  <p>On the working VM, I found a 32-bit 'allow-remote-requests', assigned a value of 1. This entry was missing from the affected machine's registry. I added it, rebooted the machine, retried the connection request.</p>
  
  <p>Still, same problem persists.</p>