Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

PowerTip: Use PowerShell to Compare Two Objects

$
0
0

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        <=


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>