r/PowerShell • • Nov 05 '26

Question WinRM with Cert auth... avoiding need to specify CertificateThumbprint?

I'm setting up a lab HyperV cluster, without a domain, so I'm kind of in the weeds already. Every recipe I'm finding online assumes functional password-less winrm between the pre-clustered nodes. I'm primarily following https://techcommunity.microsoft.com/blog/itopstalkblog/windows-server-2025-hyper-v-workgroup-cluster-with-certificate-based-authenticat/4428783 but I've found that I've had to consult a pile of different sources because they all leave out small but essential bits.

I'm nearly there, but not quite. I've made myself a root CA, generated certs, signed them, imported them, etc etc. If I Invoke-Command on Node1 like so

Invoke-Command -ComputerName Node2 { 1 } -CertificateThumbprint $certThumb

... the it works fine and dandy, and same for the other direction. But it looks like Test-Cluster, and it's WG match of Test-WorkgroupCluster don't have a means of specifying which certificate to use for auth. Clearly it's meant to automagically guess at which one to use, and whatever my machines are guessing they're getting it wrong. I'm hoping if I can get PSSession working on its own the rest will fall into place.

So does anyone know how New-PSSession decides which cert to use for remote auth? All these blogs and stuff seem to assume that it can and will, but I don't know what criteria it uses!

5 Upvotes

10 comments sorted by

2

u/gowinder 29d ago

Test-Cluster has no -CertificateThumbprint parameter, so $PSDefaultParameterValues can't help there. Push the cert choice up into the session and run the cmdlet from inside it:

$s = New-PSSession -ComputerName Node1 -CertificateThumbprint $certThumb Invoke-Command -Session $s -ScriptBlock { Test-Cluster -Node Node1,Node2 }

The client certificate gets picked once, where you can specify it, and Test-Cluster runs on the node instead of your workstation.

One more thing worth checking while you're in there: LocalMachine\My should hold exactly one cert with the Client Authentication EKU and a private key. With two matching certs the CSP picks whichever comes back first, which is the same "it guesses wrong" behaviour you're seeing.

1

u/hume_reddit 29d ago

I probably should have mentioned it in the original post, but there's no workstation involved... there's node1, node2, and nothing else. I'm running Test-WorkgroupCluster on node1. Cert:\localmachine\My has exactly one key in it on each machine.

I think I'm going to have to burn this all down and start again. I'm pretty confused at this point, since as near as I can tell the guides I'm following (multiple) shouldn't work, either.

IT's definitely not a Powershell problem, I think. Regardless, all this information here has been helpful. Especially PSDefaultParameterValues... I didn't even know that existed!

→ More replies (1)

2

u/BlackV Nov 05 '26

from my memory, it uses the dnsname or host name as the decider, then the first non expired one, which I guess is the primary reason the certificate thumbprint parameter exists

its also a pain with the native cluster cmdlets

→ More replies (4)

2

u/jborean93 29d ago

Unfortunately I don't believe the WinRM client has any automatic certificate lookup behaviour. The underlying API requires you to provide an explicit thumbprint and that's what the -CertificateThumbprint maps to from PowerShell.

You could try setting $PSDefaultParameterValues['Invoke-Command:CertificateThumbprint'] = '...' so that it might be used by default by anything calling Invoke-Command but that really depends on how Test-Cluster and other related functions are actually building the session. If they are building it from the WSManConnectionInfo class into the Runspace API then you are mostly out of luck sorry.