繁体   English   中英

如何在 PowerShell 中检索 IIS 网站的 SSL 证书

[英]How to retrieve SSL certificate of an IIS website in PowerShell

我正在尝试检索一堆 IIS 网站的证书,并将指纹与我拥有的证书匹配。 如果指纹匹配,那很好。 但是,如果指纹不匹配,那么我想将该特定证书添加到该网站。 我知道我可以使用以下方法验证所需的证书是否存在:

Get-ChildItem -Path Cert:\LocalMachine\My | Select-Object Thumbprint

我可以获取 IIS 网站并使用以下方法查看绑定:

Get-ChildItem -Path IIS:Sites | Select-Object -ExpandProperty Bindings

但是,我不知道如何检索这些网站的证书指纹。 我将目标证书的指纹存储在一个变量中,如下所示:

$CertThumbprint = "###############################"

如果我走错了路,请告诉我。 谢谢你。

首先,这不是我的代码,在这里找到的。
你可以试试这个:

Import-Module WebAdministration
$siteThumbs = Get-ChildItem IIS:SSLBindings | Foreach-Object {
    [PSCustomObject]@{
        Site       = $_.Sites.Value
        Thumbprint = $_.Thumbprint
    } 
}

这应该为您提供一个包含站点和指纹的对象数组供您比较。


从您的评论中,我收集到多个站点可以共享相同的指纹并分别列出它们,您可以这样做(未经测试)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM