I am trying to create a powershell script that pulls out the thumbprint of a certificate on a windows server so that I can use this thumbprint in a variable to use it in another command that creates a HTTPS listener.
I have managed to create the first step that works with the following command:
$thumbprint = (get-childitem -path cert:\localmachine\my | where-object {$_.subject -match $hostname+".xxx.com"}).thumbprint
So now i have the thumbprint saved in a variable.
Then i am trying to use the following command that works if i type in the contents of the $thumbprint value manually:
winrm create winrm/config/listener?Address=*+Transport=HTTPS '@{Hostname="$hostname";CertificateThumbprint="$thumbprint"}'
When running this command I get the following error:
Message = The WS-Management service cannot process the configuration request because the certificate thumbprint in the request is not a valid hex string: $thumbprint.
Does anyone know how I could solve this?
This works (manually typing the same value):
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="xxx.xxx.xxx";CertificateThumbprint="AF1D0F82070C4E3692BBF43747BAE74DED74A40A"}'
The contents of the $thumbprint variable is AF1D0F82070C4E3692BBF43747BAE74DED74A40A