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

标签 powershell vbscript iis-6

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

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



有谁知道我如何将现有的 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 文档在这里:

Managing Server Certificates by Using IISCertObj (IIS 6.0)

关于powershell - 通过 powershell 或 vbscript 以编程方式将现有的 ssl 证书分配给 iis6 中的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4585809/

相关文章:

powershell - Antlr v4 : 'mismatched input'

excel - 代码在 .vbs 文件中运行良好,但在 UFT 脚本中运行不佳 - 错误 429

.net - 我可以在.NET中设置IIS MIME类型吗?

powershell - 如何使用 PowerShell 更新现有的 IIS 6 网站

iis-6 - 可自托管和可 IIS 托管的 OWIN 项目

PowerShell:在日志文件中搜索字符串的一部分

powershell - 使用 Powershell 2.0 调用 mage 并调用运算符(即 &)

vbscript - VBS错误: "Expected end of statement"

vbscript - Asp 经典格式数字不显示最后的零

regex - PowerShell - 替换方括号?