私の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
何か助けと提案があります。ありがとう!
サーバーごとに1つの 'Invoke-Command'を作成する必要がありますか? – Didge
@Didgeさんが追加した例 –
今すぐ取得します。混乱して申し訳ありません。しかし、私は 'IIS:\ SslBindings'にアクセスできないと思います。私はいつも「ドライブが見つかりません」というエラーを受けました。 'IIS'という名前のドライブは存在しません。 これは、エラーが発生した部分です。 'Get-ChildItem -Path IIS:\ SslBindings' – Didge