我有以下在 IIS6 中创建新网站的 powershell 脚本:
有谁知道我如何将现有的 ssl 证书分配给网站?
我知道我可以使用
adsutil.vbs
设置端口号像这样:
cscript adsutil.vbs set w3svc/xxx/securebindings ":443:somewhere.com"
但是在分配现有的 ssl 证书时,我画了一个很大的空白。
最佳答案
我认为这就是你想要的:
$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)
您还可以创建 .NET 互操作程序集(通过添加对
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)
您仍然需要单独设置 SSL 端口绑定(bind),就像您已经在做的那样。
IIS.CertObj 上的 MS 文档在这里:
关于powershell - 通过 powershell 或 vbscript 以编程方式将现有的 ssl 证书分配给 iis6 中的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4585809/