Compare running services against a baseline using Powershell

Posted: April 29, 2014 in Information, Powershell, Windows General
Tags: , , ,

Some quick commands I hacked together to make it easier to check what services are running on a machine after it has restarted, and compare them against a “known good” baseline of the services that *should* be running.

The key purpose was for after a server crash to check the services such as SQL and exchange have all started again.

First, capture the “running baseline” of active services at a time when the machine is running as expected. This will create a file called “baseline.xml” with details of the running services

get-service *|where{$_.status -eq “Running”} |export-clixml baseline.xml

 

Then, to compare, run the following command. It will return only the services from the “running baseline” that are NOT running now.

compare-object (Import-clixml baseline.xml) (get-service *|where{$_.status -eq “Running”}) -property displayname | where-object {$_.sideindicator -eq “<=”}

Some services such as Windows Updates may constantly report as not running compared to the baseline as they will start and stop as needed. To prevent these “false positives” appearing in the results, check these services have been stopped just before running the baseline export.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s