PowerTip: Use PowerShell to Compare Two Objects

Doctor Scripto

Summary: Use Windows PowerShell to compare two objects to view differences and similarities.

Hey, Scripting Guy! Question How can I compare two objects and see the values that differ and exist in both?

Hey, Scripting Guy! Answer Charlotte Windows PowerShell User Group member Brian Wilhite says: There is a cmdlet that will make life easy for you. The cmdlet is Compare-Object, and it will compare two objects and detail the results. The IncludeEqual parameter will list the properties that exist in both objects.

$OneToFive = 1..5

$OneToTen = 1..10

Compare-Object -DifferenceObject $OneToFive -ReferenceObject $OneToTen –IncludeEqual

InputObject  SideIndicator

———–     ————-

          1         ==

          2         ==

          3         ==

          4         ==

          5         ==

          6         <=

          7         <=

          8         <=

          9         <=

         10        <=


Discussion is closed.

Feedback usabilla icon