I'm trying to automate installing new SSL certificates onto a Windows Server using powershell. I have most of it done but I have a small issue. When I try to update the Terminal Services SSL cert I keep getting an error and for the life of me I can't figure out why.

    $NewCert = Import-Certificate -FilePath $FileName -CertStoreLocation cert:\LocalMachine\My
    $RDPInstance = Get-CimInstance -ClassName Win32_TSGeneralSetting -Namespace ROOT\CIMV2\TerminalServices
    $RDPInstance.SSLCertificateSHA1Hash = $NewCert.Thumbprint
    Set-CimInstance -CimInstance $RDPInstance -Passthru

I took most of this code from Microsoft's site to be able to do this update but it throws the error:

    Set-CimInstance : Invalid parameter
    At line:1 char:1
    + Set-CimInstance -CimInstance $RDPInstance -Passthru
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (Win32_TSGeneral...me = "RDP-Tcp"):CimInstance) [Set-CimInstance], CimException
        + FullyQualifiedErrorId : HRESULT 0x80041008,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand

I have tried a few versions of the Set-CimInstance but all of them seem to throw the same Invalid parameter.

  • 2
    Make sure that imported certificate is in PFX form. I bet it isn't, thus without private key. As the result you can get this error. – Crypt32 Jul 20 at 17:35

Ah! I found the issue. It turns out that some of the attributes are read-only so I would be able to put the entire instance back again and that is where it was failing. I have changed it so it is now just updating the attribute SSLCertificateSHA1Hash.

Set-CimInstance -CimInstance $RDPInstance -Property @{SSLCertificateSHA1Hash=$Thumbprint} -PassThru

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.