Compare-Object

 

Additional Resources for Compare-Object

 

Comparing Two Objects or Text Files

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/compare-object.mspx

 

 

SYNOPSIS

Compares two sets of objects.

 

SYNTAX

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

 

DETAILED DESCRIPTION

Compares two sets of objects. One set of objects is the Reference set and the other 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 (indicated by the == symbol).

 

PARAMETERS

 

-referenceObject <PSObject[]>

Objects used as a reference for comparison.

 

Required?

true

Position?

1

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-differenceObject <PSObject[]>

Objects to compare to those specified as reference objects.

 

Required?

true

Position?

2

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-syncWindow <int>

Defines a search region where an attempt is made to re-sync the order if there is no match.

 

Required?

false

Position?

named

Default value

5

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-property <Object[]>

Specifies the properties of the reference and difference objects to compare.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-caseSensitive <SwitchParameter>

Indicates that comparisons should be case-sensitive.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-culture <string>

Specifies the culture to use for comparisons.

 

Required?

false

Position?

named

Default value

<default culture>

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-excludeDifferent <SwitchParameter>

Displays only the characteristics of compared objects that are equal.

 

Required?

false

Position?

named

Default value

True

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-includeEqual <SwitchParameter>

Displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and difference object are displayed.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-passThru <SwitchParameter>

Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Object

 

RETURN TYPE

Objects

 

NOTES

 

For more information, type "Get-Help Compare-Object -detailed". For technical information, type "Get-Help Compare-Object -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

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

 

This command compares the contents of two text files. It displays only those lines which appear in one or the other file, but not in both files.

 

EXAMPLE 2

 

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

 

This command compares each line of content in two text files. It displays all lines of content from both files indicating whether each line appears in only textfile1.txt or textfile2.txt or appears in both of the files.

 

EXAMPLE 3

 

$processes_before = get-process  notepad

$processes_after  = get-process

compare-object -referenceobject $processes_before -differenceobject $processes_after

 

This command compares two sets of process objects. The Get-Processcmdlet is used to retrieve the processes running on the computer and store them in the $processes_before variable. An instance of Notepad is then started. The Get-Process cmdlet is used again to retrieve the processes running on the computer and store them in the $processes_after variable. In the last line, Compare-Object is used to compare the two sets of process objects, displaying the differences between them, which includes the new instance of Notepad at least.

 

RELATED LINKS

Group-Object

Measure-Object

Sort-Object

ForEach-Object

New-Object

Select-Object

Tee-Object

Where-Object

 

 

 

500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@systemmanager.forsenergy.ru to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.