none
import certificate to certificate store and bind it to IIS using command line

    Question

  • You cannot vote on your own postHi,

    I created a certificate  ssl.cer on CA using the  certificate request.

    Now I want to import this certificate into Certificate store on the server for which request was created and bind it to IIS on port 443.

    I know how to do this using GUI.

    I  am looking to do it using command line so that I can automate it in a batch script.

    Please help me.


    Ankur

    Monday, May 21, 2012 10:05 AM

Answers

  • Here is the SDK method for installin a pfx file as a certificate.

    ' args are pfxfile, pfxfilepassword, WebFarmServers, username, password
    Set iiscertobj = WScript.CreateObject("IIS.CertObj")
    pfxfile = WScript.Arguments(0)
    pfxfilepassword = WScript.Arguments(1)
    InstanceName = WScript.Arguments(2)
    WebFarmServers = split(WScript.Arguments(3), ",")
    iiscertobj.UserName = WScript.Arguments(4)
    iiscertobj.UserPassword = WScript.Arguments(5)
    For Each IISServer in WebFarmServers
      iiscertobj.ServerName = IISServer
      iiscertobj.InstanceName = InstanceName
      iiscertobj.Import pfxfile, pfxfilepassword, true, true
    Next

    Here is how to convert a CER to a PFX.

    http://www.ehow.com/how_8586664_convert-cer-pfx.html


    ¯\_(ツ)_/¯

    Monday, May 21, 2012 3:02 PM
  • To import the certificate, I use Certutil. Take a look here for the command line reference.

    To bind the cert use netsh. Read here.


    Blog: http://scriptimus.wordpress.com/

    Monday, May 21, 2012 8:25 PM

All replies

  • Hi,

    Try a web search and then you don't need to wait for an answer in the forum. For example:

    http://lmgtfy.com/?q=import+certificate+command+line

    Bill

    Monday, May 21, 2012 2:50 PM
  • Here is the SDK method for installin a pfx file as a certificate.

    ' args are pfxfile, pfxfilepassword, WebFarmServers, username, password
    Set iiscertobj = WScript.CreateObject("IIS.CertObj")
    pfxfile = WScript.Arguments(0)
    pfxfilepassword = WScript.Arguments(1)
    InstanceName = WScript.Arguments(2)
    WebFarmServers = split(WScript.Arguments(3), ",")
    iiscertobj.UserName = WScript.Arguments(4)
    iiscertobj.UserPassword = WScript.Arguments(5)
    For Each IISServer in WebFarmServers
      iiscertobj.ServerName = IISServer
      iiscertobj.InstanceName = InstanceName
      iiscertobj.Import pfxfile, pfxfilepassword, true, true
    Next

    Here is how to convert a CER to a PFX.

    http://www.ehow.com/how_8586664_convert-cer-pfx.html


    ¯\_(ツ)_/¯

    Monday, May 21, 2012 3:02 PM
  • To import the certificate, I use Certutil. Take a look here for the command line reference.

    To bind the cert use netsh. Read here.


    Blog: http://scriptimus.wordpress.com/

    Monday, May 21, 2012 8:25 PM