Skip to content

Instantly share code, notes, and snippets.

@robderickson
Created September 21, 2018 19:38
Show Gist options
  • Save robderickson/eca37384562003431baa3b8eb77467bb to your computer and use it in GitHub Desktop.
Save robderickson/eca37384562003431baa3b8eb77467bb to your computer and use it in GitHub Desktop.
CertsExpiringNotice
#Requires -Modules PSPKI
[CmdletBinding()]
param(
[string[]]$ComputerName,
[string]$From,
[string[]]$To,
[string]$Subject,
[string]$SmtpServer
)
$HtmlBody = @()
foreach ($server in $ComputerName) {
$ExpiringCerts = Get-IssuedRequest -CertificationAuthority $server |
Where-Object {$_.NotAfter -gt (Get-Date) -and $_.NotAfter -lt ((Get-Date).AddDays(60))} |
Select-Object @{Name='RequesterName';Expression={$_ | Select-Object -ExpandProperty "Request.RequesterName"}},CommonName,NotAfter |
Sort-Object -Property NotAfter |
ConvertTo-Html -Fragment -PreContent "<h2>$server</h2>" -PostContent "<br /><br />"
$HtmlBody += $ExpiringCerts
}
$Html = @"
<html>
<head>
<style>
body {
font-family: Calibri, sans-serif;
font-size: 11pt;
}
h2 {
color: #0099ff;
}
th {
background-color: #CCC;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
$HtmlBody
</body>
</html>
"@
$Message = @{
Body = "$Html"
BodyAsHtml = $true
From = $From
SmtpServer = $SmtpServer
Subject = $Subject
To = $To
}
Send-MailMessage @Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment