PowerShell Logo Small

Compare-Object



This is the built-in help made by Microsoft for the command 'Compare-Object', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Compares two sets of objects.

SYNTAX


Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]> [-CaseSensitive] [-Culture <string>] [-ExcludeDifferent] [-Includ
eEqual] [-PassThru] [-Property <Object[]>] [-SyncWindow <int>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Compare-Object cmdlet compares two sets of objects. One set of objects is the Reference set, and the other set is the Difference set.

The result of the comparison indicates whether a property value appeared only in the object from the Reference set (indicated by the <= symbol),
only in the object from the Difference set (indicated by the => symbol) or, if the IncludeEqual parameter is specified, in both objects (indicate
d by the == symbol).



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113286
Group-Object
Measure-Object
Sort-Object
ForEach-Object
New-Object
Select-Object
Tee-Object
Where-Object

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>compare-object -referenceobject $(get-content C:\test\testfile1.txt) -differenceobject $(get-content C:\test\testfile2.txt)



Description
-----------
This command compares the contents of two text files. It displays only the lines that appear in one file or in the other file, not lines that app
ear in both files.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>compare-object -referenceobject $(get-content C:\Test\testfile1.txt) -differenceobject $(get-content C:\Test\testfile2.txt) -includeequal



Description
-----------
This command compares each line of content in two text files. It displays all lines of content from both files, indicating whether each line appe
ars in only Textfile1.txt or Textfile2.txt or whether each line appears in both files.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>$processes_before = get-process

C:\PS> notepad

C:\PS> $processes_after = get-process

C:\PS> compare-object -referenceobject $processes_before -differenceobject $processes_after



Description
-----------
These commands compare two sets of process objects.

The first command uses the Get-Process cmdlet to get the processes on the computer. It stores them in the $processes_before variable.

The second command starts Notepad.

The third command uses the Get-Process cmdlet again and stores the resulting processes in the $processes_after variable.

The fourth command uses the Compare-Object cmdlet to compare the two sets of process objects. It displaysthe differences between them, which incl
ude the new instance of Notepad.