コンテンツへスキップ

powershell 配列同士の比較

$a=@(3,2,1,5,4,8)
$b=@(4,2,3,1,5,6)
Compare-Object ($a|sort-object) ($b|sort-object) -IncludeEqual | foreach-object {
    $direction = $_.SideIndicator
    $value = $_.InputObject
    if( $direction -eq "<="){
        write-host("aにだけあり[{0}]" -f $value)
    } elseif ( $direction -eq "=>"){
        write-host("bにだけあり[{0}]" -f $value)
    } else {
        write-host("aとbにあり[{0}]" -f $value)
    }
}