Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell order sensitive Compare-Objects diff

Tags:

powershell

Is it possible to do the order comparison of items in arrays with Compare-Object aka diff in PowerShell? if not, suggest a workaround.

$a1=@(1,2,3,4,5)
$b1=@(1,2,3,5,4)
if (Compare-Object $a1 $b1) {
    Write-Host 'Wrong order '
}
else {
    Write-Host 'OK' 
}
like image 517
Ruslan Avatar asked Sep 03 '25 16:09

Ruslan


1 Answers

Use -SyncWindow 0:

$a1=@(1,2,3,4,5)
$b1=@(1,2,3,5,4)
if (Compare-Object $a1 $b1 -SyncWindow 0) {
    Write-Host 'Wrong order '
}
else {
    Write-Host 'OK' 
}

More info: Comparing Arrays in Windows PowerShell.

like image 139
beatcracker Avatar answered Sep 05 '25 14:09

beatcracker