【发布时间】:2017-10-18 20:52:03
【问题描述】:
我目前正在编写一个脚本,一旦绑定在我的 Web 服务器的 IIS 中的证书接近到期日期,它将发送一封电子邮件。我确实有通过电子邮件发送的脚本。我只需要知道如何比较商店查询中可用的证书与当前使用的证书。现在,这就是我所拥有的:
$Date= (Get-Date)
$SMTPServer = "smtp.test.com"
$From = "testmail@noreply.com"
Import-Module WebAdministration
$Servers = @("WEBSERVER1", "WEBSERVER2")
$certificates = foreach($server in $Servers){
Invoke-Command -ComputerName $server -ScriptBlock { $CertAll = Get-ChildItem -Path Cert:\LocalMachine\My }
Invoke-Command -ComputerName $server -ScriptBlock { $CertInUse = Get-ChildItem -Path IIS:\SslBindings }
Invoke-Command -ComputerName $server -ScriptBlock { $CertSame = Compare-Object -ReferenceObject $CertAll -DifferenceObject $CertInUse -Property Thumbprint -IncludeEqual -ExcludeDifferent }
Invoke-Command -ComputerName $server -ScriptBlock { $cert = $CertSame | ForEach {Get-ChildItem -Path Cert:\LocalMachine\My\$($_.thumbprint)} |
Select-Object Subject, DaysUntilExpired, NotAfter, @{n='ExpireInDays';e={($_.notafter - ($Date)).Days}}}
}
$certificates | Sort DisplayName
任何帮助和建议将不胜感激。谢谢!
【问题讨论】:
标签: powershell powershell-remoting windows-scripting