Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$services = Get-Service | Select-Object -Property MachineName,Status,Name,DisplayName | Sort-Object -Property Name
$htmlbase = $services | ConvertTo-Html -Fragment | Out-String
$xml = [xml]$htmlbase
$xml.SelectNodes("//tr/td[contains(text(),'Running')]")|ForEach-Object {$_.setattribute('class','running')}
$xml.SelectNodes("//tr/td[contains(text(),'Stopped')]")|ForEach-Object {$_.setattribute('class','stopped')}
body {font-family:Arial, Helvetica, sans-serif;}
table {border-collapse: collapse;}
table, th, td {border: 1px solid black; padding: 2px;}
td.running {background-color: green;}
td.stopped {background-color: red;}
$messagebody = ConvertTo-Html -Head $head -Body $($xml.OuterXml.ToString()) | Out-String
Send-MailMessage -To "" -From "" -SmtpServer "<smtpServerFQDN>" -Subject "Services Report" -Body $messagebody -BodyAsHtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.