我目前正在研究一个脚本,该脚本在绑定在我的Web服务器的IIS中的证书即将到期时发送一封电子邮件。我确实有脚本通过电子邮件发送。我只需要知道如何比较商店查询中可用的证书与当前正在使用的证书。现在,这是我有:Powershell脚本在IIS中远程查找当前绑定的过期证书
$Date= (Get-Date)
$SMTPServer = "smtp.test.com"
$From = "[email protected]"
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
任何帮助和建议,将不胜感激。谢谢!
我必须为每台服务器创建一个'Invoke-Command'吗? – Didge
@Didge新增示例 –
我现在明白了。对不起,先生。但我想我不能访问'IIS:\ SslBindings'。我总是得到错误,说'找不到驱动器。名称'IIS'的驱动器不存在.' 这是我认为的部分,我得到了以下错误: 'Get-ChildItem -Path IIS:\ SslBindings' – Didge