![如何使用 Powershell 脚本导出与特定 IIS 站点相关的证书详细信息](https://linux22.com/image/1615920/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20Powershell%20%E8%84%9A%E6%9C%AC%E5%AF%BC%E5%87%BA%E4%B8%8E%E7%89%B9%E5%AE%9A%20IIS%20%E7%AB%99%E7%82%B9%E7%9B%B8%E5%85%B3%E7%9A%84%E8%AF%81%E4%B9%A6%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF.png)
我编写了以下代码来仅导出与 IIS 站点相关的一台服务器的 SSL 证书详细信息,但我希望该脚本在多台服务器上运行。我该如何解决这个问题?
Import-Module -Name WebAdministration
#Number of days to look for expiring certificates
$threshold = 300
#Set deadline date
$deadline = (Get-Date).AddDays($threshold)
Get-ChildItem -Path IIS:SSLBindings | ForEach-Object -Process
{
if ($_.Sites)
{
$certificate = Get-ChildItem -Path CERT:LocalMachine/My |
Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint
[PsCustomObject]@{
ServerName = $env:COMPUTERNAME
Sites = $_.Sites.Value
CertificateIssuer = $certificate.Issuer
CertificateSubject = $certificate.Subject
CertificateDnsNameList = $certificate.DnsNameList
CertificateNotBefore = $certificate.NotBefore
CertificateNotAfter = $certificate.NotAfter
#CertificateExpiryInDays = New-TimeSpan -Start (Get-Date) -End $PSitem.NotAfter.Days
}
}
}