Compare-Object only reports _differences_ by default, requiring explicit opt-in for inclusion of _equal_ objects via -IncludeEqual.
Therefore, the only meaningful behavior when you use -ExcludeDifferent is to _default_ to -IncludeEqual.
Without that, as is currently the case, _nothing_ is ever output, so it is currently effectively pointless to pass -ExcludeDifferent _without also passing -IncludeEqual_.
Compare-Object 1,2 3, 1 -ExcludeDifferent -PassThru -IncludeEqual | Should -Be 1
# Currently produces NO output, because -IncludeEqual isn't implied.
Compare-Object 1,2 3, 1 -ExcludeDifferent -PassThru | Should -Be 1
Both tests should pass.
The 2nd test fails, because -IncludeEqual is not implied.
PowerShell Core 7.0.0-rc.2
It appears that it is already _supposed_ to do that, but clearly isn't. See Compare-Object.cs L374:
/// <summary>
/// If the parameter 'ExcludeDifferent' is present, then we need to turn on the
/// 'IncludeEqual' switch unless it's turned off by the user specifically.
/// </summary>
protected override void BeginProcessing()
{
if (ExcludeDifferent)
{
if (_isIncludeEqualSpecified == false)
{
return;
}
if (_isIncludeEqualSpecified && !_includeEqual)
{
return;
}
_includeEqual = true;
}
}
:tada:This issue was addressed in #12317, which has now been successfully released as v7.1.0-preview.3.:tada:
Handy links:
Most helpful comment
It appears that it is already _supposed_ to do that, but clearly isn't. See Compare-Object.cs L374: