Solarwinds RMM Certificate Check

by Luxx
2 minutes

Just a copy from  here     with a fix to also check the "webhosting" certificate store for expiring certificates... (may not be the best script ever..) 

Get-ChildItem -Recurse | where { $_.notafter -le (get-date).AddDays(75) -AND $_.notafter -gt (get-date)} | select thumbprint, subject

# List All SSL Certificates Expiring in X Days

$DaysToExpired = 30   #Number of days to look for expiring certificates

$CountExpired = 0

$deadline = (Get-Date).AddDays($DaysToExpired)   #Set deadline date

Dir Cert:\LocalMachine\my | foreach {

  If ($_.NotAfter -le $deadline) { $_ | Select Issuer, Subject, NotAfter, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}}

  $CountExpired = $CountExpired + 1

  }

  }

Dir Cert:\LocalMachine\webhosting | foreach {

  If ($_.NotAfter -le $deadline) { $_ | Select Issuer, Subject, NotAfter, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}}

  $CountExpired = $CountExpired + 1

  }

  }

If ($CountExpired -gt 0)

{

  Write-Host("You Have $CountExpired Certificates Expiring in less than $DaysToExpired Days.")

  Exit 1001

}else{

  Write-Host("No Certificates Expiring in less than $DaysToExpired Days.")

  Exit 0

}