Search code examples
asp.netiissslwindows-server

How to completely script the process of importing SSL certificate and binding this certificate to a specific site


I have been looking around for a solution for this problem that works across different versions of Windows Server & IIS, but so far I couldn't find a reasonable solution, what I need is some sort of a script or a command line tool, that takes a certificate file (pfx) for example and then either using the same script or tool find a way to configure one website to use this certificate.


Solution

  • I found a good script on TechNet

    http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/96ccb49f-b669-4e05-965e-3090984a3594.mspx?mfr=true

    CertImport.vbs

    Option Explicit
    Dim iiscertobj, pfxfile, pfxfilepassword, InstanceName, WebFarmServers, IISServer
    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