현재 웹 서버의 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