Comparing Multidimensional Arrays Using PowerShell
Comparing Multidimensional Arrays Using PowerShell
Summary
This TechNet Wiki is based on the Forum Post
Requirement
Need PowerShell Code to compare two multi dimension arrays. It should result difference set of values in multi dimension arrays.
Input
001 002 |
$A=@((1,A,D),(2,B,K),(3,C,X),(4,D,L)) $B=@((1,A,D),(2,B,K),(2S,J,T),(3,C,X),(4,D,L)) |
The multi dimension array is incorrect so we need to fix this like shown below
001 002 |
$A=@(('1','A','D'),('2','B','K'),('3','C','X'),('4','D','L')) $B=@(('1','A','D'),('2','B','K'),('2S','J','T'),('3','C','X'),('4','D','L')) |
Now let's use Compare-Object to meet the requirement
001 002 003 004 005 |
$A=@(('1','A','D'),('2','B','K'),('3','C','X'),('4','D','L')) $B=@(('1','A','D'),('2','B','K'),('2S','J','T'),('3','C','X'),('4','D','L')) Compare-Object -ReferenceObject $B -DifferenceObject $A |
Help/h3>
001 002 003 004 005 006 007 |
help Compare-Object help Compare-Object -Examples help Compare-Object -Parameter ReferenceObject help Compare-Object -Parameter DifferenceObject |