Beta 42

Research and Development

Menu

PowerShell - Comparing Services

Compare-Object is one of the most widely ignored most powerful cmdlet around. It can compare results and figure out differences.

For example, if you'd like to know the differences in service configuration between two machines, here's the simple solution:

$pc1 = Get-Service -ComputerName server1
$pc2 = Get-Service -ComputerName server2 
Compare-Object $pc1 $pc2 -Property Name, Status -PassThru | Sort-Object -Property Name | `
  Select-Object -Property MachineName, Name, Status

This sample code assumes that you do have permissions to retrieve the services remotely from server1 and server2. This is just a sample to get you going with Compare-Object. You can compare anything, including folder content or information retrieved by WMI.