unexpected values in Windows RDP certificates depending on the command

Posted by fjleon@reddit | sysadmin | View on Reddit | 3 comments

we have two different tools, maintained and developed by separate teams.

Tool 1 needs to know the thumbprint of the RDP certificate, and uses this method:

$computerName = (Get-CimInstance -ClassName Win32_ComputerSystem).Name

(Get-CimInstance -Namespace "root\CIMV2\TerminalServices" -ClassName Win32_TSGeneralSetting ` -ComputerName $computerName -Filter "TerminalName='RDP-Tcp'").SSLCertificateSHA1Hash

Tool 2 instead uses this method:

$cert_info = Get-ChildItem Cert:\LocalMachine\'Remote Desktop'\ $thumbprint = $cert_info.Thumbprint

We are finding out that if the RDP certificate gets deleted, somehow Tool 1 is still showing the old thumbprint. In other words, it gets cached. The second tool does not show the thumbprint at this point since that's being deleted.

I could not find any hints in the Microsoft documentation that WMI is cached, but other posts do suggest this.

Besides rewriting tool 1 to use the second tool's method, is there any way to get reliable results?