diff --git a/reference/5.1/Microsoft.PowerShell.Utility/Compare-Object.md b/reference/5.1/Microsoft.PowerShell.Utility/Compare-Object.md index 9a379e5dc44c..57bc7e2868de 100644 --- a/reference/5.1/Microsoft.PowerShell.Utility/Compare-Object.md +++ b/reference/5.1/Microsoft.PowerShell.Utility/Compare-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 06/11/2024 +ms.date: 09/11/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -54,12 +54,15 @@ with each value on a separate line. - `Testfile1.txt` contains the values: dog, squirrel, and bird. - `Testfile2.txt` contains the values: cat, bird, and racoon. -The output displays only the lines that are different between the files. `Testfile1.txt` is the -**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with -content that appear in both files aren't displayed. +The output displays only the lines that are different between the files. Lines with content that +appear in both files aren't displayed. ```powershell -Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt) +$objects = @{ + ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt) + DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt) +} +Compare-Object @objects ``` ```Output @@ -71,13 +74,21 @@ dog <= squirrel <= ``` +For this example, the output shows the following information + +- `cat` and `racoon` are found in the difference object file, but missing from the reference object + file +- `dog` and `squirrel` are found in the reference object file, but missing from the difference + object file + ### Example 2 - Compare each line of content and exclude the differences -This example uses the **IncludeEqual** and **ExcludeDifferent** parameters to compare each line of -content in two text files. +This example uses the **ExcludeDifferent** parameter to compare each line of content in two text +files. -Because the command uses the **ExcludeDifferent** parameter, the output only contains lines -contained in both files, as shown by the **SideIndicator** (`==`). +As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred +and the output only contains lines contained in both files, as shown by the **SideIndicator** +(`==`). ```powershell $objects = @{ @@ -176,7 +187,12 @@ output displayed by the default format for **System.Boolean** objects didn't dis In this example, we compare two different string that have the same length. ```powershell -Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual +$objects = @{ + ReferenceObject = 'abc' + DifferenceObject = 'xyz' + Property = 'Length' +} +Compare-Object @objects -IncludeEqual ``` ```Output diff --git a/reference/7.4/Microsoft.PowerShell.Utility/Compare-Object.md b/reference/7.4/Microsoft.PowerShell.Utility/Compare-Object.md index 9141242a7809..4aee55ee12e4 100644 --- a/reference/7.4/Microsoft.PowerShell.Utility/Compare-Object.md +++ b/reference/7.4/Microsoft.PowerShell.Utility/Compare-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 06/11/2024 +ms.date: 09/11/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -20,8 +20,8 @@ Compares two sets of objects. ``` Compare-Object [-ReferenceObject] [-DifferenceObject] - [-SyncWindow ] [-Property ] [-ExcludeDifferent] [-IncludeEqual] [-PassThru] - [-Culture ] [-CaseSensitive] [] + [-SyncWindow ] [-Property ] [-ExcludeDifferent] [-IncludeEqual] + [-PassThru] [-Culture ] [-CaseSensitive] [] ``` ## DESCRIPTION @@ -54,12 +54,15 @@ with each value on a separate line. - `Testfile1.txt` contains the values: dog, squirrel, and bird. - `Testfile2.txt` contains the values: cat, bird, and racoon. -The output displays only the lines that are different between the files. `Testfile1.txt` is the -**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with -content that appear in both files aren't displayed. +The output displays only the lines that are different between the files. Lines with content that +appear in both files aren't displayed. ```powershell -Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt) +$objects = @{ + ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt) + DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt) +} +Compare-Object @objects ``` ```Output @@ -71,10 +74,17 @@ dog <= squirrel <= ``` +For this example, the output shows the following information + +- `cat` and `racoon` are found in the difference object file, but missing from the reference object + file +- `dog` and `squirrel` are found in the reference object file, but missing from the difference + object file + ### Example 2 - Compare each line of content and exclude the differences -This example uses the **ExcludeDifferent** parameter to compare each line of -content in two text files. +This example uses the **ExcludeDifferent** parameter to compare each line of content in two text +files. As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred 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 In this example, we compare two different string that have the same length. ```powershell -Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual +$objects = @{ + ReferenceObject = 'abc' + DifferenceObject = 'xyz' + Property = 'Length' +} +Compare-Object @objects -IncludeEqual ``` ```Output diff --git a/reference/7.5/Microsoft.PowerShell.Utility/Compare-Object.md b/reference/7.5/Microsoft.PowerShell.Utility/Compare-Object.md index a188bdf14b91..329409254de1 100644 --- a/reference/7.5/Microsoft.PowerShell.Utility/Compare-Object.md +++ b/reference/7.5/Microsoft.PowerShell.Utility/Compare-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 06/11/2024 +ms.date: 09/11/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -54,9 +54,8 @@ with each value on a separate line. - `Testfile1.txt` contains the values: dog, squirrel, and bird. - `Testfile2.txt` contains the values: cat, bird, and racoon. -The output displays only the lines that are different between the files. `Testfile1.txt` is the -**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with -content that appear in both files aren't displayed. +The output displays only the lines that are different between the files. Lines with content that +appear in both files aren't displayed. ```powershell $objects = @{ @@ -75,10 +74,17 @@ dog <= squirrel <= ``` +For this example, the output shows the following information + +- `cat` and `racoon` are found in the difference object file, but missing from the reference object + file +- `dog` and `squirrel` are found in the reference object file, but missing from the difference + object file + ### Example 2 - Compare each line of content and exclude the differences -This example uses the **ExcludeDifferent** parameter to compare each line of -content in two text files. +This example uses the **ExcludeDifferent** parameter to compare each line of content in two text +files. As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred and the output only contains lines contained in both files, as shown by the **SideIndicator** diff --git a/reference/7.6/Microsoft.PowerShell.Utility/Compare-Object.md b/reference/7.6/Microsoft.PowerShell.Utility/Compare-Object.md index 099aeb18c728..274c624b0077 100644 --- a/reference/7.6/Microsoft.PowerShell.Utility/Compare-Object.md +++ b/reference/7.6/Microsoft.PowerShell.Utility/Compare-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 06/11/2024 +ms.date: 09/11/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.6&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -20,8 +20,8 @@ Compares two sets of objects. ``` Compare-Object [-ReferenceObject] [-DifferenceObject] - [-SyncWindow ] [-Property ] [-ExcludeDifferent] [-IncludeEqual] [-PassThru] - [-Culture ] [-CaseSensitive] [] + [-SyncWindow ] [-Property ] [-ExcludeDifferent] [-IncludeEqual] + [-PassThru] [-Culture ] [-CaseSensitive] [] ``` ## DESCRIPTION @@ -54,12 +54,15 @@ with each value on a separate line. - `Testfile1.txt` contains the values: dog, squirrel, and bird. - `Testfile2.txt` contains the values: cat, bird, and racoon. -The output displays only the lines that are different between the files. `Testfile1.txt` is the -**reference** object (`<=`) and `Testfile2.txt`is the **difference** object (`=>`). Lines with -content that appear in both files aren't displayed. +The output displays only the lines that are different between the files. Lines with content that +appear in both files aren't displayed. ```powershell -Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt) +$objects = @{ + ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt) + DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt) +} +Compare-Object @objects ``` ```Output @@ -71,10 +74,17 @@ dog <= squirrel <= ``` +For this example, the output shows the following information + +- `cat` and `racoon` are found in the difference object file, but missing from the reference object + file +- `dog` and `squirrel` are found in the reference object file, but missing from the difference + object file + ### Example 2 - Compare each line of content and exclude the differences -This example uses the **ExcludeDifferent** parameter to compare each line of -content in two text files. +This example uses the **ExcludeDifferent** parameter to compare each line of content in two text +files. As of PowerShell 7.1, when using the **ExcludeDifferent** parameter, **IncludeEqual** is inferred 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 In this example, we compare two different string that have the same length. ```powershell -Compare-Object -ReferenceObject 'abc' -DifferenceObject 'xyz' -Property Length -IncludeEqual +$objects = @{ + ReferenceObject = 'abc' + DifferenceObject = 'xyz' + Property = 'Length' +} +Compare-Object @objects -IncludeEqual ``` ```Output