Powershell IIS7 管理单元将 SSL 证书分配给 https 绑定

发布于 2024-08-28 11:53:47 字数 173 浏览 6 评论 0原文

作为自动化构建过程的一部分,我们使用 powershell 脚本废弃并重建 IIS 站点。

创建 AppPool 和包含绑定信息的网站后,我想为 https 绑定设置 SSL 证书。我在网上找不到任何具体的例子来证明这一点。

有什么想法吗?

寻找一位仁慈的powershell神...

As part of our automated build procedure we are trashing and reconstructing our IIS site with powershell scripts.

Once i have created the AppPool and the website complete with binding information I want to set the SSL certificate for the https binding. I can't find any concrete examples onl;ine anywhere that demonstrate this.

Any ideas?

Looking for a benevolent powershell god...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌上芳菲 2024-09-04 11:53:47

您可以将前面的示例与在网站中创建 https 绑定合并。

import-module webadministration
$computerName = $Env:Computername
$domainName = $Env:UserDnsDomain
New-WebBinding -Name "MyWebSite" -IP "*" -Port 443 -Protocol https
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

You can merge previous examples with creation of an https binding in a web site.

import-module webadministration
$computerName = $Env:Computername
$domainName = $Env:UserDnsDomain
New-WebBinding -Name "MyWebSite" -IP "*" -Port 443 -Protocol https
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443
勿挽旧人 2024-09-04 11:53:47

以下是简单的操作方法:

首先识别您要分配的证书并获取其指纹

,例如您的证书可能位于 cert:\LocalMachine\Root

您可以通过以下方式获取指纹:

$thumb = (Get-ChildItem cert:\LocalMachine\Root | where-object { $_.Subject -like "YOUR STRING HERE*" } | Select-Object -First 1).Thumbprint

<<<现在可以将证书分配给 IP 地址和端口 comme ci >>>

$IPAddress = 101.100.1.90

$port = 443

Push-Location IIS:\SslBindings

Get-Item cert:\LocalMachine\Root\$thumb | New-Item $IPAddress!$port

Pop-Location

希望这对任何人都有帮助

Here is how to do it simply:

First identify thecertificate that you want to assign and obtain it's thumbprint

e.g. Your certificate might be in cert:\LocalMachine\Root

You can obtain the thumbprint with the following:

$thumb = (Get-ChildItem cert:\LocalMachine\Root | where-object { $_.Subject -like "YOUR STRING HERE*" } | Select-Object -First 1).Thumbprint

<<< Now one can assign the certificate to an ip address and port comme ci >>>

$IPAddress = 101.100.1.90

$port = 443

Push-Location IIS:\SslBindings

Get-Item cert:\LocalMachine\Root\$thumb | New-Item $IPAddress!$port

Pop-Location

Hope this is of help to anyone

入画浅相思 2024-09-04 11:53:47

您可以使脚本更简单,如下所示:

Get-ChildItem cert:\LocalMachine\Root | where { $_.Subject -like "YOUR STRING HERE*" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

使用 0.0.0.0 来定位所有托管 IP(相当于 IIS 管理器中的“*”)或根据需要将其替换为特定 IP。

You can make the script simpler like this:

Get-ChildItem cert:\LocalMachine\Root | where { $_.Subject -like "YOUR STRING HERE*" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

Use 0.0.0.0 to target all hosted IP's (equivalent to "*" in IIS Manager) or replace it with a specific IP if needed.

隔岸观火 2024-09-04 11:53:47

我在这里找到了一个关于如何分配证书的示例。

http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/

但是,似乎没有非常优雅,必须对证书指纹进行硬编码
...所以如果有人知道更好的方法,我很高兴听到。

I've found an example here on how one can assign the certificate.

http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/

However, it doesn't seem very elegant having to hard code the certificate thumbprint
... so if any one knows of a better method, I'd be glad to hear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文