PowerShell order sensitive Compare-Objects diff

后端 未结 2 1863
说谎
说谎 2021-01-21 16:44

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

         


        
2条回答
  •  醉话见心
    2021-01-21 17:30

    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.

提交回复
热议问题