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'
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With