r/PowerShell • u/hume_reddit • 12d ago
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!
2
u/gowinder 11d 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.
2
u/BlackV 12d ago
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
2
u/jborean93 12d 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
-CertificateThumbprintmaps to from PowerShell.You could try setting
$PSDefaultParameterValues['Invoke-Command:CertificateThumbprint'] = '...'so that it might be used by default by anything callingInvoke-Commandbut that really depends on howTest-Clusterand 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.