PowerShell: The client cannot connect to the destination specified in the request

54.6k views Asked by At

My goal is to execute the PowerShell file on remote server through TFS tasks 'PowerShell on Target Machines' for that Steps I have taken so far are:

Both Build and remote server already enabled

Enable-PSRemoting -Force

also added the trusthost server IPs added

Set-Item wsman:\localhost\client\trustedhosts *

and

Restart-Service WinRM

after doing all above steps still got the following error on TFS task

##[error]Connecting to remote server 'REMOTE SERVER IP' 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.

What will be the reason or what I am missing any thing.

2

There are 2 answers

1
Jane Ma-MSFT On BEST ANSWER

Here are some possible causes for the error and some troubleshooting advices:

Advice 1

This problem may occur if the Window Remote Management service and its listener functionality are broken.

To resolve this problem, follow these steps:

Step1. Install the latest Windows Remote Management update.

Step2. Run the following command to restore the listener configuration:

winrm invoke Restore winrm/Config

Step3. Run the following command to perform a default configuration of the Windows Remote Management service and its listener:

winrm quickconfig

Click this document for detailed information.

Advice 2

The group policy configuration of fire wall exception may be incorrect. A configuration error in the policy results in an empty value for the ListeningOn property. Use the following command to check the value.

PS> Get-WSManInstance winrm/config/listener -Enumerate

Click this document for detailed information and how to solve the issue.

Adivce 3

The possible cause of the question is the error settings of HTTP proxy. Because PowerShell remoting uses the HTTP protocol, it is affected by HTTP proxy settings.

To resolve this problem:

Step1. Use the ProxyAccessType, ProxyAuthentication, and ProxyCredential parameters of the New-PSSessionOption cmdlet to create a session option object with the proxy settings for your enterprise. Save the option object is a variable.

Step2. Use the variable that contains the option object as the value of the SessionOption parameter of a New-PSSession, Enter-PSSession, or Invoke-Command command.

Click this document for detailed information.

Advice 4

Try running your PowerShell file locally and see if it has the same error.

0
Dongolo Jeno On

In my case the problem was that the service WinRM was not running. It was manual start by default.

After starting the service from services the problem was gone.