PowerShell 顺序敏感比较对象差异

Гро*_*ный 3 powershell

是否可以在 PowerShell 中使用Compare-Objectakadiff对数组中的项目进行顺序比较?如果没有,建议一个解决方法。

$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' 
}
Run Code Online (Sandbox Code Playgroud)

bea*_*ker 5

使用-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' 
}
Run Code Online (Sandbox Code Playgroud)

更多信息:在 Windows PowerShell 中比较数组