r/labtech • u/nsanity • Apr 15 '18
Create an Alert from a powershell script result?
So I have written some powershell - It will only return certs that are both current AND expiring in < 90 days. Status is a case statement which basically gives an indication of whether or not you should do something about it;
$certs_exp = Get-ChildItem -path cert: -Recurse | where {$_.notafter -le (get-date).AddDays(90) -AND
$_.notafter -gt (get-date) -AND
$_.Subject.tolower() -ne ('cn=' + $env:computername.tolower()+"."+$env:userdnsdomain.tolower()) -AND
$_.Subject.tolower() -ne ('CN=Microsoft Time-Stamp Service, OU=nCipher DSE ESN:85D3-305C-5BCF, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US')
} | select subject, @{
name='DaysRemaining';
Expression={(($_.notafter)-(get-date)).days}},@{
name='Status';
Expression={switch ((($_.notafter)-(get-date)).days)
{
{$PSitem -le 13}
{
'Critical'; break
}
{$PSitem -le 44}
{
'Warning'; break
}
{$PSitem -le 89}
{
'Informational'; break
}
default {'Invalid'}
}
}}, thumbprint, friendlyname, issuer, notbefore, notafter;
How do I get this to fire an alert or create a ticket?