For remoting to work properly, the local computer must send its communications to a port on which the remote computer is listening. If either computer uses the wrong port, the communication is not received.

By default, Windows PowerShell remoting uses port 5985 for HTTP transport. This default port is used whenever a remote command does not include the ConnectionURI or Port parameters.

If you send a remote command a port on which the remote computer is not listening, Windows PowerShell generates the following error message.

  Copy Code
ERROR:  The connection to the specified remote host was refused. Verify that the WS-Management service is running on the remote host and configured to listen for requests on the correct port and HTTP URL.

To specify an alternate port

  • Use the Port or ConnectionURI parameter in a remote command.

    For example, the following command uses the Port parameter to send the connection request to port 8080.

      Copy Code
    invoke-command -computername Server01 -port 8080 -script {dir ${env:ProgramFiles(x86)}
    

To change the default port used for a remote command

  1. Use the Set-Item cmdlet in the WSMan: drive to change the Port value in the Listener leaf node.

    For example, the following command changes the default port for WSMan communication on the local computer to 8080.

      Copy Code
    set-item wsman:\localhost\listener\listener*\port -value 8080
    

See Also