NoSpamProxy Forum

Normale Version: Script: Ausgabe der Zertifikate mit Fehlern
Sie sehen gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo,
hier ein angepasstes Script vom Original
https://github.com/noSpamProxy/Reports/t...Quarantine

Problem war folgender: Man bekommt leider vom NSP keine Info wenn von einem Absender die CA Zertifikate nicht vorhanden sind. Bsp. wenn hier eine Eigene CA verwendet wird - Allianz,Lidl, etc) 

Daher habe ich das Script angepasst, welches alle Zertifikate ausgibt, deren Status nicht in Ordnung sind.

Der Aufruf bleibt gleich wie beim Original Script.

get-certificatesWithProblems.ps1 -SMTPHost xxx.xxx.xxx.xxx -ReportRecipient "Empfaeger@diedomain.de"

[attachment=188]

@Stefan
Kann dann ggf. auch gerne in die Script Sammlung rein.
Optional würde es sich sicherlich auch kombinieren lassen und per Parameter auswählen lassen was man möchte.

get-certificatesWithProblems.ps1 -ReportType Q -SMTPHost xxx.xxx.xxx.xxx -ReportRecipient "Empfaeger@diedomain.de"

Q = Quarantäne
E = mit Error

Gerne kann es mal jemand probieren mit Zertifikaten in Quarantäne, da ich selbst keine hab Smile

Code:
<#
.SYNOPSIS
  Name: CheckNspCertificates.ps1
  Check certificates with Errors - where  certification authorities or intermediate certificates are missing

.NOTES
  Version:        1.0.0
  Author:         NoSpamProxy
    Purpose/Change: inital creation

   Version: 1.0.2
   Author: Frank Fischer - freaky-media
   Purpose/Change: Get Certificates in Quarantine or Certificates with Error/Problems
#>

param (
    [Parameter(Mandatory=$true)][string] $ReportType,
    [Parameter(Mandatory=$true)][string] $SMTPHost,
    [Parameter(Mandatory=$false)][string] $ReportSender = "NoSpamProxy Report Sender <nsp@zweckverband-gdv.de>",
    [Parameter(Mandatory=$true)][string] $ReportRecipient,
    [Parameter(Mandatory=$false)][string] $ReportSubject = "Zertifikate mit Problemen oder in Quarantaene"
   
)
$certificatesInQuarantineOrError = $null
$certificatesInQuarantineOrErrorCount = $null
$reportFileName = $Env:TEMP + "\certificatereport.html"
$htmltitle = $null
$htmlcaption = $null


if($ReportType -eq "Q")
{
   
   
    # begin with Certs in Quarantine
    Write-Host "Getting certificates in quarantine..."
    $certificatesInQuarantineOrError = get-nspcertificate -StoreIds Quarantined  
   

    if ($certificatesInQuarantineOrError -eq $null){
    Write-Host "No certificates in Quarantine!"
    exit

    }
    $htmltitle = "Zertifikat(e) in Quarant&auml;ne"
    $htmlcaption = "Zertifikat(e) in Quarant&auml;ne"

    }

    elseif($ReportType -eq "E")
    {
    Write-Host "Getting all certificates except the status OK/NoError ..."
    $certificatesInQuarantineOrError = get-nspcertificate -StoreIds All | Where-Object {$_.Status -ne "NoError"}
   
    if ($certificatesInQuarantineOrError -eq $null){
    Write-Host "No certificates with Problems!"
    exit
    }
    $htmltitle = "Zertifikat(e) mit Probleme(n)"
    $htmlcaption = "Zertifikat(e) mit Probleme(n)"
    }
    else
    {
    Write-Host "ReportType not given or false use Q for Quarantine or E for Error"
    exit
    }

   
$certificatesInQuarantineOrErrorCount = $certificatesInQuarantineOrError.Count

foreach ($certificate in $certificatesInQuarantineOrError){

$certificatesInStatus = $certificate.Status
    $certificateSubjectDN = $certificate.SubjectDistinguishedName
    $certificateIssuerDN = $certificate.IssuerDistinguishedName
    $certificateValidity = $certificate.ValidTo
    $certificatesInStatus = $certificate.Status
    $htmlbody2 += "<tr><td width=150px>"+$certificateSubjectDN+"</td><td>"+$certificateIssuerDN+"</td><td>"+$certificateValidity+"</td><td>"+$certificatesInStatus+"</td></tr>"
}

$htmlbody1 ="<html>
            <head>
                <title>"+$htmltitle+"</title>
                <style>
                    table, td, th { border: 1px solid black; border-collapse: collapse; }
                    #headerzeile         {background-color: #DDDDDD;}
                </style>
            </head>
        <body style=font-family:arial>
            <h1>"+$certificatesInQuarantineOrErrorCount+" "+$htmlcaption+"</h1>
            <br>
            <table>
                <tr id=headerzeile>
                    <td><h3>SubjectDistinguishedName</h3></td><td><h3>IssuerDistinguishedName</h3></td><td><h3>ValidTo</h3></td><td><h3>Status</h3></td>
                </tr>
                "

$htmlbody3="</table>
        </body>
        </html>"
$htmlout=$htmlbody1+$htmlbody2+$htmlbody3
$htmlout | Out-File $reportFileName
Send-MailMessage -SmtpServer $SmtpHost -From $ReportSender -To $ReportRecipient -Subject $ReportSubject -Body "Im Anhang dieser E-Mail finden Sie den Bericht mit der Auswertung der Zertifikate, fuer den Status Quarantaene oder Fehler. Details entnehmen Sie bitte dem Anhang." -Attachments $reportFileName
Write-Host "Doing some cleanup.."
Remove-Item $reportFileName
Write-Host "Done."


# SIG # Begin signature block
# MIIMSwYJKoZIhvcNAQcCoIIMPDCCDDgCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUIs6tIhndCmdlG0YhMbLCwdH/
# lwKgggmqMIIElDCCA3ygAwIBAgIOSBtqBybS6D8mAtSCWs0wDQYJKoZIhvcNAQEL
# BQAwTDEgMB4GA1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoT
# Ckdsb2JhbFNpZ24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMTYwNjE1MDAwMDAw
# WhcNMjQwNjE1MDAwMDAwWjBaMQswCQYDVQQGEwJCRTEZMBcGA1UEChMQR2xvYmFs
# U2lnbiBudi1zYTEwMC4GA1UEAxMnR2xvYmFsU2lnbiBDb2RlU2lnbmluZyBDQSAt
# IFNIQTI1NiAtIEczMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjYVV
# I6kfU6/J7TbCKbVu2PlC9SGLh/BDoS/AP5fjGEfUlk6Iq8Zj6bZJFYXx2Zt7G/3Y
# SsxtToZAF817ukcotdYUQAyG7h5LM/MsVe4hjNq2wf6wTjquUZ+lFOMQ5pPK+vld
# sZCH7/g1LfyiXCbuexWLH9nDoZc1QbMw/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# KoZIhvcNAQEBBQAEggEAR4HMvrRW8q5+6+7OYhX5P0nCStfewBC3tXaPoFunOGhQ
# 3XyQRqIwe1LKzQ9z4r8vZGbaRQIsIAALmXvjLlrYVxqt07pxn/mp9t3gwgy8YMS5
# sMihApTAq+IYbTbTh08n3D1QBxo91UK68eUwF16PpgHQKMqB4sqnL+/VH9jy4unG
# U5WwUVhAztKCmD57Us8DHuppDg2uXJHjy1NYimBLgsZv1l0VDChjlSGDQfP2hvUn
# NJ60HpJV5NeIxmk8IKVWtSRLBb64hCWm/KqYbYt88pF0iP6uqBPMgzygyiEXTsMM
# wiP7V3zBUZY1b7ZSExkONvwBSjPvbgJxfCp7ajKntw==
# SIG # End signature block
Moin,
früher in der Schule hätte ich jetzt "oller Streber" gesagt. ;-)
Super Sache! Ich möchte Jan da jetzt nicht vorweggreifen, aber das wird sicherlich ohne weitere möglich sein. Am Ende des Tages ist er der Herr des Githubs. :-)
Gruß Stefan