I'm trying to create a Windows Poweshell monitor that will look for expiring certs by examining the certs in the localmachine\my store of the cert drive of a computer. I have the following code but when I press the "Get Script Output" button on the Edit Script dialog I always receive "Not Defined". I've looked at the Part 1, 2, and 3 of "The Basics of PowerShell - THWACK" articles but I can't seem to diagnose my issue. Any help would be appreciated.
sl cert:
sl \
sl .\\LocalMachine\My\
$certs = Get-ChildItem | Where-Object {($_.Notafter - (Get-Date)).Days -le 30}
[int]$status = 0
if ($certs.Count -gt 0) {
$status = 2
foreach ($cert in $certs) {
if (($cert.NotAfter - (Get-Date)).Days -le 7) {
$status = 3
}
}
}
$stat = $certs.Count
Write-Host "Message.CertCount : $stat certificates expiring"
Write-Host "Statistic.CertCount : $stat"
exit $status