In the first article in this series I explained the goal. I want to help you create a server monitoring dashboard with nothing more than a few PowerShell scripts and a web server. Before we build the web site, we need to create the scripts that gather the information and create the HTML reports.

In an article a while back, I showed how to use PowerShell to list stopped automatic services and suggested that you might want to output the data to HTML. That is exactly what we’re going to do here.

param (
[string] $list,
[string] $outputpath

$style = "&lt;style<span>&lt;/style&gt;BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + ""</span>

Function Problems {
$servers = Get-Content $list

Foreach ($server in $servers)
{Get-Service -ComputerName $server |where {($_.StartType -eq "Automatic") -and ($_.Status -match "Stopped|.*Starting|.*Paused") -and
($_.Name -notmatch "CDPSvc.*|.*gupdate|.*RemoteRegistry|.*MapsBroker|.*sppsvc|.*WbioSrvc|.*iphlpsvc|.*tiledatamodelsvc|.*clr_optimization_v4.0.30319_64|
select @{n="Server";e={$server}}, @{n="Stopped Service";e={$_.displayname }}

$report = Problems|Sort-Object Server|ConvertTo-Html -Head $style|Out-String

#Send-MailMessage -SmtpServer -From -To -Subject "Stopped Server Services" -Priority High -BodyAsHtml:$true -Body $report}

$report|out-file -FilePath $outputpath

The script above is written to use two parameters when called, -list should be the path to a text file containing the severs you want to scan. The -outputpath parameter is the location to save the HTML report.

You’ll notice the $ -notmatch section contains several service names. These services are set to automatic but do not keep running if they don’t have work to do. The regex pattern keeps these services from showing up in the report as false positives. You may need to add a few more for your environment, especially .Net versions.

There’s also an option to email a copy of the report. Just un-remark the line and populate the sever name and addresses. The HTML report will be embedded in the email, not attached.

In the next post for this series, we’ll generate a system status report to go along with the events and services, then we’ll put them all together in a dashboard.