Contact Info

Crumbtrail » 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 the properties of objects

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

-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.
        Make comparisons case-sensitive.
    -culture string
        The culture to use for comparisons.
        Display only the characteristics of compared objects that are equal.
        Displays characteristics of compared objects that are equal.
        By default only differences are displayed.
        Pass the object created by this cmdlet through the pipeline. 

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

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
 $proc_after = get-process
 compare-object -referenceobject $proc_before -differenceobject $proc_after