0

I am trying to connect to vm using run powershell on target machine task using classic editor to trigger a python code which needs to be downloaded from artifact on the target machine (here, vm). I am getting an error " The SSL certificate contains a common name (CN) that does not match the hostname. " I have tried to change settings in certificate snap-in but it still gave me same error.

  • Based on the error message, the issue occurs when you create a VM without a DNS Name Label for your public IP, and then later add one (something like example.centralus.cloudapp.azure.com). It can also occur if you change the DNS name label. – VenkateshDodda Dec 27 '21 at 05:24
  • You can refer this [SO thread](https://stackoverflow.com/questions/42538540/the-ssl-certificate-contains-a-common-name-cn-that-does-not-match-the-hostnam)or [MSDN forum discussion](https://social.msdn.microsoft.com/Forums/en-US/4dcc3a95-5191-4619-84f2-b1589744657d/the-ssl-certificate-contains-a-common-name-cn-that-does-not-match-the-hostname?forum=TFService) to resolve your issue. – VenkateshDodda Dec 27 '21 at 05:24
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 02 '22 at 21:25

1 Answers1

0

Thank you @VenkateshDodda-MT & @srbrills Posting your suggestion as an answer to help other community members.

The server certificate on the TARGET system, not the host file or the build agent, is the problem. 

The problem happens when you build an Azure VM without a DNS Name Label for your public IP and then add one afterwards (something like example.centralus.cloudapp.azure.com). It can also happen if the DNS name label is changed.

  • You need to make sure that, what address you want to use to connect to the machine. This is the target machine address.

On the target machine, open PowerShell as an administrator. Enter the following command.

New-SelfSignedCertificate -DnsName WhateverTargetMachineAddressYouNeed -CertStoreLocation Cert:\LocalMachine\My

Enter the following commands one at a time in PowerShell.

winrm delete winrm/config/listener?Address=*+Transport=HTTPS

Then:

winrm create winrm/config/listener?Address=*+Transport=HTTPS '@{Hostname="WhateverTargetMachineAddressYouNeed";CertificateThumbprint="TheThumbprintYouCopied";port="5986"}'
AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15