Comparing Service Configuration

by Sep 22, 2014

PowerShell 3 and later

Provided you have PowerShell remoting up and running on two servers, here is a simple script that illustrates how you can get the state of all services from each server and then calculate the differences between the two servers.

$Server1 = 'myServer1'
$Server2 = 'someOtherServer'

$services1 = Invoke-Command { Get-Service } -ComputerName $Server1 | 
  Sort-Object -Property Name, Status

$services2 = Invoke-Command { Get-Service } -ComputerName $Server2 | 
  Sort-Object -Property Name, Status

Compare-Object -ReferenceObject $services1 -DifferenceObject $services2 -Property Name, Status -PassThru |
  Sort-Object -Property Name 

The result is a list with only the differences in service configuration.

Twitter This Tip! ReTweet this Tip!