0
0
PowerShellscripting~10 mins

Compare-Object for differences in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compare two arrays and show differences.

PowerShell
$array1 = @(1, 2, 3)
$array2 = @(2, 3, 4)
Compare-Object $array1 [1] $array2
Drag options to blanks, or click blank then click option'
A-DifferenceObject
B-InputObject
C-CompareObject
D-ReferenceObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ReferenceObject' instead of '-DifferenceObject' causes errors.
2fill in blank
medium

Complete the code to show only differences without side indicators.

PowerShell
Compare-Object -ReferenceObject $list1 -DifferenceObject $list2 [1]
Drag options to blanks, or click blank then click option'
A-IncludeEqual
B-ExcludeDifferent
C-PassThru
D-NoSideIndicator
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-PassThru' shows objects but keeps side indicators.
3fill in blank
hard

Fix the error in the code to compare two files and show differences.

PowerShell
$file1 = Get-Content file1.txt
$file2 = Get-Content file2.txt
Compare-Object $file1 [1] $file2
Drag options to blanks, or click blank then click option'
A-ReferenceObject
B-DifferenceObject
C-InputObject
D-CompareObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ReferenceObject' for the second file causes wrong comparison.
4fill in blank
hard

Fill both blanks to compare two lists and show only items unique to the first list.

PowerShell
Compare-Object -ReferenceObject $listA -DifferenceObject $listB [1] [2]
Drag options to blanks, or click blank then click option'
A-PassThru
B-IncludeEqual
C-ExcludeDifferent
D-SideIndicator '<='
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-IncludeEqual' shows equal items, not differences.
5fill in blank
hard

Fill all three blanks to compare two arrays and output only items unique to either list.

PowerShell
$result = Compare-Object [1] [2] [3]
Drag options to blanks, or click blank then click option'
A-ReferenceObject $arrayX
B-DifferenceObject $arrayY
C-PassThru
D-IncludeEqual
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-IncludeEqual' includes equal items, not just differences.