WinRM client received an HTTP status code 502 or 403 from the remote WS-Management service.

Yesterday Sandeep Venkata was testing a change when he observed that releases to both azure environment as well as standard environment are failing with following errors: -

Azure environment: -

Failed to connect to the remote server <xyz>.cloudapp.net, the following error message was returned: WinRM client received an HTTP status code 502 from the remote WS-Management service. For more information, please see the help topic of about_Remote_Troubleshooting.

Standard environment: -

Failed to connect to the remote server <xyz>.mydomain.com, the following error message was returned: WinRM client received an HTTP status code 403 from the remote WS-Management service. For more information, please see the help topic of about_Remote_Troubleshooting

He tried executing the remote power-shell scripts directly from the RM server box and observed the same failure. On digging deeper, he observed that WinHTTP proxy (this is different from IE proxy settings) on the RM Server machine was configured to use a proxy which was causing connectivity issues to both azure and standard environments.

To come out of this, he ran the following command from an Admin prompt:
                netsh winhttp show proxy      –    View current proxy settings
                netsh winhttp reset proxy      --    Reset winhttp proxy settings to connect directly.

Enjoy !!