[英]How to retrieve SSL certificate of an IIS website in PowerShell
I'm trying to retrieve the certificate of a bunch of IIS websites and match the thumbprint with a certificate that I have.我正在尝试检索一堆 IIS 网站的证书,并将指纹与我拥有的证书匹配。 If the thumbprint is matched, that's perfectly fine.如果指纹匹配,那很好。 However, if the thumbprint is not matched then I want to add that specific certificate to that website.但是,如果指纹不匹配,那么我想将该特定证书添加到该网站。 I know I can verify if the desired certificate exists using:我知道我可以使用以下方法验证所需的证书是否存在:
Get-ChildItem -Path Cert:\LocalMachine\My | Select-Object Thumbprint
And I can get the IIS websites and look at bindings using:我可以获取 IIS 网站并使用以下方法查看绑定:
Get-ChildItem -Path IIS:Sites | Select-Object -ExpandProperty Bindings
However, I can't figure out how I can retrieve the certificate thumbprint of these websites.但是,我不知道如何检索这些网站的证书指纹。 I have the target certificate's thumbprint stored in a variable like so:我将目标证书的指纹存储在一个变量中,如下所示:
$CertThumbprint = "###############################"
If I am going at it the wrong way, please let me know.如果我走错了路,请告诉我。 Thank you.谢谢你。
First of all, this is not my code, found that here .首先,这不是我的代码,在这里找到的。
You can try this perhaps:你可以试试这个:
Import-Module WebAdministration
$siteThumbs = Get-ChildItem IIS:SSLBindings | Foreach-Object {
[PSCustomObject]@{
Site = $_.Sites.Value
Thumbprint = $_.Thumbprint
}
}
This should give you an array of objects with both the sites and the thumbprints for you to compare.这应该为您提供一个包含站点和指纹的对象数组供您比较。
From your comment, I gather more than one site can share the same thumbprint and to list them separately, you could do this (untested)从您的评论中,我收集到多个站点可以共享相同的指纹并分别列出它们,您可以这样做(未经测试)
Import-Module WebAdministration
$siteThumbs = Get-ChildItem IIS:SSLBindings | Foreach-Object {
$thumb = $_.Thumbprint
foreach ($site in $_.Sites.Value) {
[PSCustomObject]@{
Site = $site
Thumbprint = $thumb
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.