title: Unable to use PowerShell Enter-PSSession to connect to remote server
body: <p>I am having problems connecting to a remote server using PowerShell where the remote machine uses a non-default port number.  The setup is as follows:  I have a virtual host server with several virtual machines.  All of these virtual machines have the same IP address but are accessed with a different port, for example:</p>
  
  <pre><code>a.b.c.d:3000
  a.b.c.d:3001
  etc
  </code></pre>
  
  <p>So, the PowerShell script I have so far is:</p>
  
  <pre><code>$password = ConvertTo-SecureString "&lt;MyPassword&gt;" -AsPlainText -Force
  $cred= New-Object System.Management.Automation.PSCredential ("&lt;Domain\UserName&gt;", $password)
  Enter-PSSession -ComputerName &lt;IPAddress&gt; -Port &lt;PortNumber&gt; -Credential $cred
  </code></pre>
  
  <p>The bits inside the "&lt;>" are specific to the individual machines.  When running this script I get the following error:</p>
  
  <blockquote>
    <p>Enter-PSSession : Connecting to remote server 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 o n the destination to
    analyze and configure the WinRM service: "winrm quickconfig". For more
    information, see the about_Remote_Troubleshooting H elp topic. At
    C:\PowerShell\Test7.ps1:25 char:16
    + Enter-PSSession &lt;&lt;&lt;&lt;  -ComputerName  -Port  -Credential $cred
        + CategoryInfo          : InvalidArgument: (:String) [Enter-PSSession], PSRemotingTransportException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed</p>
  </blockquote>
  
  <p>Another variant I tried is as follows:</p>
  
  <pre><code>$password = ConvertTo-SecureString "&lt;MyPassword&gt;" -AsPlainText -Force
  $cred= New-Object System.Management.Automation.PSCredential ("&lt;Domain\UserName&gt;", $password)
  $powershell_uri = "http://&lt;IPAddress&gt;:&lt;PortNumber&gt;"
  Enter-PSSession -ConnectionUri $powershell_uri -Credential $cred
  </code></pre>
  
  <p>but this gave the following error:</p>
  
  <blockquote>
    <p>Enter-PSSession : Connecting to remote server 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 o n the destination to
    analyze and configure the WinRM service: "winrm quickconfig". For more
    information, see the about_Remote_Troubleshooting H elp topic. At
    C:\PowerShell\Test7.ps1:21 char:16
    + Enter-PSSession &lt;&lt;&lt;&lt;  -ConnectionUri $powershell_uri -Credential $cred  # -ComputerName  -Port  -Credential
    $cred
        + CategoryInfo          : InvalidArgument: (http://:/:Uri) [Enter-PSSession],
    PSRemotingTransportException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed</p>
  </blockquote>
  
  <p>I have set the TrustedHosts on my local machine (winrm set winrm/config/client @{TrustedHosts=""}) and on the remote machine I have run the "winrm quickconfig" command. On the remote machine I have also run the "winrm create winrm/config/listener?Address=*+Transport=HTTP @{Port=""}" command.</p>
  
  <p>Any assistance on how I can establish a connection within PowerShell to these machines would be greatly appreciated.</p>