How do I programmably get the thumbprint a self-signed certificate just created programmably in Powershell using New-SelfSignedCertificate... RRS feed

  • Question

  • User-858993849 posted

    I am trying to automate creating of self-signed certificates, and thus creating a script in PowerShell and using New-SelfSignedCertificate to create the certificates.

    Successful creation of a new certificate creates a new thumbprint.  I am wanting to grab that thumbprint programmably and put it in a variable to use later.

    How do I do that?

    Friday, April 6, 2018 1:38 PM

All replies

  • User283571144 posted


    According to your description, I suggest you could try to use System.Management.Automation dll to run the powershell script creating the certificate.

    Then you could get the result of  powershell script output.

    More details, you could refer to below codes:

            static void Main(string[] args)
                PSDataCollection<PSObject> outputCollection = new PSDataCollection<PSObject>();
                PowerShell psinstance = PowerShell.Create();
                string Script = @"New-SelfSignedCertificate -DnsName 'www.fabrikam.com', 'www.contoso.com' -CertStoreLocation 'cert:\LocalMachine\My'";
                var result = psinstance.BeginInvoke<PSObject, PSObject>(null, outputCollection);
                foreach (PSObject outputItem in outputCollection)
                    //TODO: handle/process the output items if required



    Best Regards,


    Wednesday, April 11, 2018 2:56 AM