0
0
PowerShellscripting~5 mins

Compare-Object for differences in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PowerShell cmdlet <code>Compare-Object</code> do?

Compare-Object compares two sets of objects and shows the differences between them.

It helps find what is unique to each set or what is missing.

Click to reveal answer
beginner
What does the SideIndicator property show in Compare-Object output?

SideIndicator tells which input the difference belongs to:

  • <= means the object is only in the first set.
  • => means the object is only in the second set.
Click to reveal answer
beginner
How do you compare two text files line by line using Compare-Object?

Use Get-Content to read each file, then compare:

Compare-Object (Get-Content file1.txt) (Get-Content file2.txt)
Click to reveal answer
beginner
What parameter do you use with Compare-Object to show matching lines?

Use -IncludeEqual to show lines that are the same in both sets.

Click to reveal answer
intermediate
Can Compare-Object compare objects other than strings? Give an example.

Yes, it can compare any objects, like numbers or custom objects.

Example:

$a = 1,2,3; $b = 2,3,4; Compare-Object $a $b
Click to reveal answer
What does the SideIndicator value '<=' mean in Compare-Object output?
AObject is only in the first set
BObject is only in the second set
CObject is in both sets
DObject is missing from both sets
Which cmdlet reads file content line by line for comparison?
ACompare-Object
BSet-Content
CNew-Item
DGet-Content
How do you show matching lines in Compare-Object output?
A-ExcludeEqual
B-HideMatches
C-IncludeEqual
D-ShowDifferencesOnly
Can Compare-Object compare arrays of numbers?
AOnly files
BYes
COnly strings
DNo
What is the default behavior of Compare-Object when comparing two sets?
AShows only differences
BShows only matching lines
CShows all differences and matching lines
DDeletes matching lines
Explain how to use Compare-Object to find differences between two text files.
Think about reading files and comparing line by line.
You got /4 concepts.
    Describe what the SideIndicator symbols mean in the output of Compare-Object.
    Focus on which side the difference belongs to.
    You got /2 concepts.