Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 1.0 » Compare-Object

Compare-Object - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Compare-Object

Description
Compare the properties of objects

Usage
Compare-Object [-referenceObject] PSObject[] [-differenceObject] PSObject[] 
	      [-syncWindow int] [-property Object[]] [-caseSensitive]
            [-culture string] [-excludeDifferent] [-includeEqual]
               [-passThru] [CommonParameters]

Options
-referenceObject PSObject[]
        Object(s) used as a reference for comparison.
        
    -differenceObject PSObject[]
        Object(s) to compare to the reference object(s).
        
    -syncWindow int
        Defines a search region where an attempt is made to re-sync the order if there is no match.
        
    -property Object[]
        Properties of the objects to compare.
        
    -caseSensitive
        Make comparisons case-sensitive.
        
    -culture string
        The culture to use for comparisons.
        
    -excludeDifferent
        Display only the characteristics of compared objects that are equal.
        
    -includeEqual 
        Displays characteristics of compared objects that are equal.
        By default only differences are displayed.
        
    -passThru
        Pass the object created by this cmdlet through the pipeline. 

    CommonParameters
        common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
Compare the content of two text files:

PS C:\>compare-object -referenceobject $(get-content C:\file1.txt) $(get-content C:\file2.txt)

Compare the processes running before and after starting a copy of notepad.exe, using Get-Process to retrieve the processes running and store them in a variable:

 PS C:\>$proc_before = get-process
 notepad
 $proc_after = get-process
 compare-object -referenceobject $proc_before -differenceobject $proc_after