简体   繁体   English

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

[英]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.

相关问题 如何使用PowerShell将SSL证书添加到azure网站? - How to add an SSL certificate to an azure website using powershell? 如何使用PowerShell从网站下载SSL证书? - How to download the SSL certificate from a website using PowerShell? 将现有的SSL证书与IIS网站相关联 - Associate existing SSL certificate to IIS Website 绑定后将SSL证书分配给网站-Powershell - Assign SSL Certificate to Website After Binding - Powershell 如何通过Powershell脚本设置IIS 10.0管理服务SSL证书以允许Web部署? - How do I set the IIS 10.0 Management Service SSL Certificate via a Powershell script to allow Web Deploy? 如何使用powershell安装和配置IIS、SSL证书、urlrewrite、git和克隆仓库 - How to use powershell to install and configure IIS, SSL certificate, urlrewrite, git and clone repository 如何使用 Powershell 查找仅 IIS 的 SSL 证书何时过期以获取来自 OU 的服务器列表? - How can I use Powershell to find when an SSL certificate expires for ONLY IIS for a list of servers from OU? 使用PowerShell将IIS SSL证书分配给与主机标头绑定 - Assign IIS SSL Certificate to Binding with Host Header using PowerShell 从powershell创建自签名的iis ssl证书 - Create self signed iis ssl certificate from powershell Powershell IIS7 Snap in将SSL证书分配给https绑定 - Powershell IIS7 Snap in Assign SSL certificate to https binding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM