-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
When comparing two sets of objects, it is currently somewhat cumbersome to retrieve only those objects exclusive to one side of the comparison:
$left = 1, 2, 3, 4
$right = 1, 3, 4, 5
# Left-side only: -> 2
(Compare-Object $left $right | Where-Object SideIndicator -eq '<=').InputObject
# Right-side only: -> 5
(Compare-Object $left $right | Where-Object SideIndicator -eq '=>').InputObjectWishful thinking:
$left = 1, 2, 3, 4
$right = 1, 3, 4, 5
# Left-side only: -> 2
Compare-Object $left $right -LeftOnly -PassThru
# Right-side only: -> 5
Compare-Object $left $right -RightOnly -PassThru-
-LeftOnlyand-RightOnlywould be mutually exclusive and incompatible with-ExcludeDifferent -
The existing
-PassThruswitch omits the custom-object wrapper with the side indicator that is created by default (despite the documentation claiming "Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output." - see Compare-Object's -PassThru switch is documented incorrectly MicrosoftDocs/PowerShell-Docs#1461). -
To achieve left-"join" and right-"join" logic, simply add the existing
-IncludeEqualswitch.
Note: I'm using "join" in double quotes, because no joining (merging of data) in the usual sense happens - only different or identical objects are returned.
Note that the left / right terminology is not currently part of Compare-Object, but I feel it is descriptive and intuitive (cf. SQL join terminology).
Thus, additionally, the following parameter aliases could be introduced:
-LeftObjectas an alias for-ReferenceObject-RightObjectas an alias for-DifferenceObject
Environment data
PowerShell Core v6.0.0-beta.4