通过powershell或vbscript以编程方式将现有的ssl证书分配给iis6中的网站

dag*_*da1 4 vbscript powershell iis-6

我有以下powershell脚本在IIS6中创建一个新网站:

https://github.com/dagda1/iis6/blob/master/create-site.ps1

有谁知道如何将现有的ssl证书分配给网站?

我知道我可以使用adsutil.vbs这样设置端口号:

cscript adsutil.vbs set w3svc/xxx/securebindings ":443:somewhere.com"

但是,在分配现有的ssl证书时,我正在画一个大空白.

Kev*_*Kev 5

我想这就是你想要的:

$w3svc = "W3SVC/566412209"     # <-- W3SVC/[iis number]
$pfxPath = "c:\ssl\myssl.pfx"
$pfxPassword = "password123"   # Whatever the certificate file's password is

$certMgr = New-Object -ComObject IIS.CertObj
$certMgr.ServerName = [System.Environment]::MachineName
$certMgr.InstanceName = $w3svc
$certMgr.Import($pfxPath, $pfxPassword, $true, $true)
Run Code Online (Sandbox Code Playgroud)

您还可以创建.NET Interop程序集(通过添加C:\WINDOWS\system32\inetsrv\certobj.dll或引用COM引用tlbimp.exe),以便您可以使用PowerShell和.NET项目:

[void][reflection.assembly]::loadfrom("Interop.CERTOBJLib.dll")
$certMgr = new-object -typeName CERTOBJLib.IISCertObjClass
$certMgr.ServerName = [System.Environment]::MachineName
$certMgr.InstanceName = $w3svc
$certMgr.Import($pfxPath, $pfxPassword, $true, $true)
Run Code Online (Sandbox Code Playgroud)

您仍然需要单独设置SSL端口绑定.

IIS.CertObj上的MS文档在这里:

使用IISCertObj管理服务器证书(IIS 6.0)