Skip to content

Commit 47352e9

Browse files
Update Compare-Object.md (#12346)
* Update Compare-Object.md Added line 77 for explaining sideindicators in the example section for easier understanding. * Editorial and copy changes to other versions --------- Co-authored-by: Sean Wheeler <[email protected]>
1 parent eb7fcbb commit 47352e9

File tree

4 files changed

+88
-36
lines changed

4 files changed

+88
-36
lines changed

reference/5.1/Microsoft.PowerShell.Utility/Compare-Object.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/11/2024
5+
ms.date: 09/11/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -54,12 +54,15 @@ with each value on a separate line.
5454
- `Testfile1.txt` contains the values: dog, squirrel, and bird.
5555
- `Testfile2.txt` contains the values: cat, bird, and racoon.
5656

57-
The output displays only the lines that are different between the files. `Testfile1.txt` is the
58-
**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with
59-
content that appear in both files aren't displayed.
57+
The output displays only the lines that are different between the files. Lines with content that
58+
appear in both files aren't displayed.
6059

6160
```powershell
62-
Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt)
61+
$objects = @{
62+
ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt)
63+
DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt)
64+
}
65+
Compare-Object @objects
6366
```
6467

6568
```Output
@@ -71,13 +74,21 @@ dog <=
7174
squirrel <=
7275
```
7376

77+
For this example, the output shows the following information
78+
79+
- `cat` and `racoon` are found in the difference object file, but missing from the reference object
80+
file
81+
- `dog` and `squirrel` are found in the reference object file, but missing from the difference
82+
object file
83+
7484
### Example 2 - Compare each line of content and exclude the differences
7585

76-
This example uses the **IncludeEqual** and **ExcludeDifferent** parameters to compare each line of
77-
content in two text files.
86+
This example uses the **ExcludeDifferent** parameter to compare each line of content in two text
87+
files.
7888

79-
Because the command uses the **ExcludeDifferent** parameter, the output only contains lines
80-
contained in both files, as shown by the **SideIndicator** (`==`).
89+
As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred
90+
and the output only contains lines contained in both files, as shown by the **SideIndicator**
91+
(`==`).
8192

8293
```powershell
8394
$objects = @{
@@ -176,7 +187,12 @@ output displayed by the default format for **System.Boolean** objects didn't dis
176187
In this example, we compare two different string that have the same length.
177188

178189
```powershell
179-
Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual
190+
$objects = @{
191+
ReferenceObject = 'abc'
192+
DifferenceObject = 'xyz'
193+
Property = 'Length'
194+
}
195+
Compare-Object @objects -IncludeEqual
180196
```
181197

182198
```Output

reference/7.4/Microsoft.PowerShell.Utility/Compare-Object.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/11/2024
5+
ms.date: 09/11/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -20,8 +20,8 @@ Compares two sets of objects.
2020

2121
```
2222
Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]>
23-
[-SyncWindow <Int32>] [-Property <Object[]>] [-ExcludeDifferent] [-IncludeEqual] [-PassThru]
24-
[-Culture <String>] [-CaseSensitive] [<CommonParameters>]
23+
[-SyncWindow <Int32>] [-Property <Object[]>] [-ExcludeDifferent] [-IncludeEqual]
24+
[-PassThru] [-Culture <String>] [-CaseSensitive] [<CommonParameters>]
2525
```
2626

2727
## DESCRIPTION
@@ -54,12 +54,15 @@ with each value on a separate line.
5454
- `Testfile1.txt` contains the values: dog, squirrel, and bird.
5555
- `Testfile2.txt` contains the values: cat, bird, and racoon.
5656

57-
The output displays only the lines that are different between the files. `Testfile1.txt` is the
58-
**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with
59-
content that appear in both files aren't displayed.
57+
The output displays only the lines that are different between the files. Lines with content that
58+
appear in both files aren't displayed.
6059

6160
```powershell
62-
Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt)
61+
$objects = @{
62+
ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt)
63+
DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt)
64+
}
65+
Compare-Object @objects
6366
```
6467

6568
```Output
@@ -71,10 +74,17 @@ dog <=
7174
squirrel <=
7275
```
7376

77+
For this example, the output shows the following information
78+
79+
- `cat` and `racoon` are found in the difference object file, but missing from the reference object
80+
file
81+
- `dog` and `squirrel` are found in the reference object file, but missing from the difference
82+
object file
83+
7484
### Example 2 - Compare each line of content and exclude the differences
7585

76-
This example uses the **ExcludeDifferent** parameter to compare each line of
77-
content in two text files.
86+
This example uses the **ExcludeDifferent** parameter to compare each line of content in two text
87+
files.
7888

7989
As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred
8090
and the output only contains lines contained in both files, as shown by the **SideIndicator**
@@ -177,7 +187,12 @@ output displayed by the default format for **System.Boolean** objects didn't dis
177187
In this example, we compare two different string that have the same length.
178188

179189
```powershell
180-
Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual
190+
$objects = @{
191+
ReferenceObject = 'abc'
192+
DifferenceObject = 'xyz'
193+
Property = 'Length'
194+
}
195+
Compare-Object @objects -IncludeEqual
181196
```
182197

183198
```Output

reference/7.5/Microsoft.PowerShell.Utility/Compare-Object.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/11/2024
5+
ms.date: 09/11/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.5&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -54,9 +54,8 @@ with each value on a separate line.
5454
- `Testfile1.txt` contains the values: dog, squirrel, and bird.
5555
- `Testfile2.txt` contains the values: cat, bird, and racoon.
5656

57-
The output displays only the lines that are different between the files. `Testfile1.txt` is the
58-
**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with
59-
content that appear in both files aren't displayed.
57+
The output displays only the lines that are different between the files. Lines with content that
58+
appear in both files aren't displayed.
6059

6160
```powershell
6261
$objects = @{
@@ -75,10 +74,17 @@ dog <=
7574
squirrel <=
7675
```
7776

77+
For this example, the output shows the following information
78+
79+
- `cat` and `racoon` are found in the difference object file, but missing from the reference object
80+
file
81+
- `dog` and `squirrel` are found in the reference object file, but missing from the difference
82+
object file
83+
7884
### Example 2 - Compare each line of content and exclude the differences
7985

80-
This example uses the **ExcludeDifferent** parameter to compare each line of
81-
content in two text files.
86+
This example uses the **ExcludeDifferent** parameter to compare each line of content in two text
87+
files.
8288

8389
As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred
8490
and the output only contains lines contained in both files, as shown by the **SideIndicator**

reference/7.6/Microsoft.PowerShell.Utility/Compare-Object.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 06/11/2024
5+
ms.date: 09/11/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -20,8 +20,8 @@ Compares two sets of objects.
2020

2121
```
2222
Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]>
23-
[-SyncWindow <Int32>] [-Property <Object[]>] [-ExcludeDifferent] [-IncludeEqual] [-PassThru]
24-
[-Culture <String>] [-CaseSensitive] [<CommonParameters>]
23+
[-SyncWindow <Int32>] [-Property <Object[]>] [-ExcludeDifferent] [-IncludeEqual]
24+
[-PassThru] [-Culture <String>] [-CaseSensitive] [<CommonParameters>]
2525
```
2626

2727
## DESCRIPTION
@@ -54,12 +54,15 @@ with each value on a separate line.
5454
- `Testfile1.txt` contains the values: dog, squirrel, and bird.
5555
- `Testfile2.txt` contains the values: cat, bird, and racoon.
5656

57-
The output displays only the lines that are different between the files. `Testfile1.txt` is the
58-
**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with
59-
content that appear in both files aren't displayed.
57+
The output displays only the lines that are different between the files. Lines with content that
58+
appear in both files aren't displayed.
6059

6160
```powershell
62-
Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt)
61+
$objects = @{
62+
ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt)
63+
DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt)
64+
}
65+
Compare-Object @objects
6366
```
6467

6568
```Output
@@ -71,10 +74,17 @@ dog <=
7174
squirrel <=
7275
```
7376

77+
For this example, the output shows the following information
78+
79+
- `cat` and `racoon` are found in the difference object file, but missing from the reference object
80+
file
81+
- `dog` and `squirrel` are found in the reference object file, but missing from the difference
82+
object file
83+
7484
### Example 2 - Compare each line of content and exclude the differences
7585

76-
This example uses the **ExcludeDifferent** parameter to compare each line of
77-
content in two text files.
86+
This example uses the **ExcludeDifferent** parameter to compare each line of content in two text
87+
files.
7888

7989
As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred
8090
and the output only contains lines contained in both files, as shown by the **SideIndicator**
@@ -177,7 +187,12 @@ output displayed by the default format for **System.Boolean** objects didn't dis
177187
In this example, we compare two different string that have the same length.
178188

179189
```powershell
180-
Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual
190+
$objects = @{
191+
ReferenceObject = 'abc'
192+
DifferenceObject = 'xyz'
193+
Property = 'Length'
194+
}
195+
Compare-Object @objects -IncludeEqual
181196
```
182197

183198
```Output

0 commit comments

Comments
 (0)