Radagast
Radagast

Reputation: 1096

powershell compare two arrays, create third array with only nonmatching values

Firstly the only thing I have available is powershell. I have figured out how to compare two arrays; however, I am having a bit if difficulty figuring out how to get the data back in the format I need.

$foo = @(100, 200 ,300 ,400 ,500 ,600 ,700 ,800 ,900 ,1000)
$bar = @(50, 100, 600 , 900)

Desired results would be an array with the following information

 50, 200, 300, 400, 500, 700, 800, 1000

Note that the like values

100, 600 , 900

are dropped and

50 

which is in the second array is added to the output.

is this possible?

thanks

Upvotes: 3

Views: 16370

Answers (1)

ravikanth
ravikanth

Reputation: 25810

Compare-Object is your friend:

PS C:\Users> $foo = @(100, 200 ,300 ,400 ,500 ,600 ,700 ,800 ,900 ,1000)
PS C:\Users> $bar = @(50, 100, 600 , 900)
PS C:\Users> Compare-Object $foo $bar -PassThru
50
200
300
400
500
700
800
1000

Upvotes: 14

Related Questions