diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs index 5ee48da98de..ae6e48180e5 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs @@ -372,18 +372,13 @@ private void Emit(OrderByPropertyEntry entry, string sideIndicator) #region Overrides /// - /// If the parameter 'ExcludeDifferent' is present, then we need to turn on the - /// 'IncludeEqual' switch unless it's turned off by the user specifically. + /// If the parameter 'ExcludeDifferent' is present, then the 'IncludeEqual' + /// switch is turned on unless it's turned off by the user specifically. /// protected override void BeginProcessing() { if (ExcludeDifferent) { - if (_isIncludeEqualSpecified == false) - { - return; - } - if (_isIncludeEqualSpecified && !_includeEqual) { return; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index 55819fba180..3f8a521cb15 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -76,10 +76,10 @@ Describe "Compare-Object" -Tags "CI" { { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should -Throw } - It "Should give a 0 array when using excludedifferent switch without also using the includeequal switch" { - $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent + It "Should only display equal lines when excludeDifferent switch is used without the includeequal switch" { + $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent - $actualOutput.Length | Should -Be 0 + $actualOutput.Length | Should -Be 2 } It "Should only display equal lines when excludeDifferent switch is used alongside the includeequal switch" { @@ -88,6 +88,12 @@ Describe "Compare-Object" -Tags "CI" { $actualOutput.Length | Should -Be 2 } + It "Should give a 0 array when using excludedifferent switch when also setting the includeequal switch to false" { + $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent -IncludeEqual:$false + + $actualOutput.Length | Should -Be 0 + } + It "Should be able to pass objects to pipeline using the passthru switch" { { Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should -Not -Throw }