Exchangemaster GmbH company logo

Exchangemaster GmbH - A Swiss IT Consultancy
Services
References
Partners
Contact
Getting Started
FAQs
Presentations
Articles
Community
Search
Popular
Tell-a-Friend
Follow Me

Follow exchangemaster on Twitter

Who's Online
We have 124 guests online
Syndicate
FAQ 000120 - Use PowerShell to compare services on two computers PDF Print E-mail
User Rating: / 13
PoorBest 
Written by Dejan Foro   
Oct 09, 2013 at 12:49 PM

This article applies to:

Windows Server 2008 R2

 

This script performs a comparison of services on 2 computers and create a list of services that are different.
    It will list services:
        - that exist on one machine but not on the other
        - that exist on both machines but do not have the same StartUp setting (Manual, Auto, etc.)
        - that exist on both machines but do not have the same State (Running, Stopped, etc. )
        - that exist on both machines but do ne have the same Status (OK or not)

 

<#
.NAME
    CompareServices
.VERSION
    v1.0
.AUTHOR
    Dejan Foro,
    Exchangemaster GmbH, www.exchangemaster.net
.DATE
    04 October 2013
.DESCRIPTION
   This scripts performs a comparison of services on 2 computers and create a list of services that are different.
     It will list services:
        - that exist on one machine but not on the other
        - that exist on both machines but do not have the same StartUp setting (Manual, Auto, etc.)
        - that exist on both machines but do not have the same State (Running, Stopped, etc. )
        - that exist on both machines but do ne have the same Status (OK or not)

 #>

Clear-Host
Write-Host
Write-Host "Script Name: CompareServices 1.0"
Write-Host "Author: Dejan Foro, Exchangemaster GmbH, www.exchangemaster.net"
$Date = Get-Date -DisplayHint DateTime
Write-Host "Output created on: " , $Date
Write-Host

$ServicesOnComputer1 = $Null
$ServicesOnComputer2 = $Null

Do
{
    $Computer1 = Read-Host "Computer1"
    try
    {
    $ServicesOnComputer1 = Get-WMIObject -ComputerName $Computer1 -Class Win32_service -ErrorAction Stop
    }
    Catch [Exception]
    {
    Write-Host "The host entered does not exist or cannot be contacted. Please try again"
    }
}
until ($ServicesOnComputer1 -ne $Null)

Do
{
    $Computer2 = Read-Host "Computer2"
    try
    {
    $ServicesOnComputer2 = Get-WMIObject -ComputerName $Computer2 -Class Win32_service -ErrorAction Stop
    }
    Catch [Exception]
    {
    Write-Host "The host entered does not exist or cannot be contacted. Please try again"
    }
}
until ($ServicesOnComputer2 -ne $Null)

Compare-Object -ReferenceObject $ServicesOnComputer1 -DifferenceObject $ServicesOnComputer2 -Property Name, StartMode, State, Status -PassThru `
| Sort-Object DisplayName, SystemName `
| Select-Object SystemName, DisplayName, StartMode, State, Status `
| Format-Table -AutoSize

 

 

 

SAMPLE OUTPUT        
Computer1: SERVER01
Computer2: SERVER02

SystemName DisplayName                              StartMode State   Status
---------- -----------                              --------- -----   ------
SERVER01   Application Management                   Manual    Running OK
SERVER02   Application Management                   Manual    Stopped OK
SERVER01   PsKill                                   Manual    Stopped OK
SERVER01   WinHTTP Web Proxy Auto-Discovery Service Manual    Running OK
SERVER02   WinHTTP Web Proxy Auto-Discovery Service Manual    Stopped OK

Last Updated ( Oct 09, 2013 at 09:56 AM )
<Previous   Next>