Comparing
The Compare-Object
command can be used to compare two collections of objects with one another.
Compare-Object
must be supplied with values for the ReferenceObject
and DifferenceObject
parameters, which are normally collections or arrays of objects. If either value is null, then an error will be displayed. If both values are equal, Compare-Object
does not return anything by default. For example, the reference and difference objects in the following example are identical:
Compare-Object -ReferenceObject 1, 2 -DifferenceObject 1, 2
If there are differences, Compare-Object
displays the results, as shown here:
PS> Compare-Object -ReferenceObject 1, 2, 3, 4 -DifferenceObject 1, 2
InputObject SideIndicator
----------- -------------
3 <=
4 <=
This shows that ReferenceObject
(the collection on the left, denoted by the direction of the <=
arrow) has the values, but DifferenceObject
(the collection on the right) does not.
Compare...