Okay . . . bare bones it is!
$NotRunning = Get-WmiObject win32_service -Filter "startmode = 'auto' AND state != 'running' AND Exitcode !=0 " -ComputerName sql1 |
Select-Object name, startname, exitcode
If ($NotRunning) {
$s = $NotRunning | Out-String
$body = @"
Dear ITadmin,
Your machine is in trouble! The following services aren't running:
$s
"@
Send-MailMessage -To 'ITadmin@emailsrv.com' -From alerts 'alerts@emailsrv.com' -Body $body -SmtpServer 'smtp.domain.com'
}