Jump to content


Recommended Posts

Hello Jesse,

 

i just put that idea into a tiny script because that is something i will be end up using too. So thank's for the idea.

Just create a daily scheduled task that runs the script.

#####################################################################################################################
$rserver = 'smtprelay.mydomain' # your smtp relay server
$rport = '25' # your smtp relay server port
$from = 'sccm@mydomain' # make sure to edit mydomain
$to = 'my.name@mydomain' # your email address here
$subject = "IIS Certificate of $env:COMPUTERNAME expires soon"
$body = "The IIS certificate of $env:COMPUTERNAME is about to expire soon (xxx). Time to wake up mate."
$ipport = '0.0.0.0:443' # modify if you need to
$days = '30' # grace period before the script starts bothering you
######################################################################################################################

$warn = (Get-Date).AddDays($days)
$cmd = [string]"& netsh http show sslcert ipport={0}" -f $ipport
$certhash = (((Invoke-Expression $cmd | Where-Object {$_ -match 'Certificate Hash'}) -split ':')[1]).trim()
$cert = Get-ChildItem Cert:\LocalMachine\My -ErrorAction SilentlyContinue | Where-Object {$_.Thumbprint -eq $certhash}
$certexpire = $cert.NotAfter
if($certexpire -le $warn){
  $body = $body -replace 'xxx', $cert.NotAfter
  Send-MailMessage -SmtpServer $rserver -Port $rport -Subject $subject -From $from -To $to -Body $body
}

So long

Peter

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.