PowerShellのdiffはCompare-Objectコマンドレットになります。
実際にCompare-Objectを使った使用例を以下に記します。
・ファイルの比較をしてみる 比較の構文は以下のようになります。
Compare-Object (Get-Content ファイル) (Get-Content ファイル)
以下のテキストファイルを2つ用意し、Compare-Objectコマンドレットで比較した時の出力です。
Windows 3.1 Windows 95 Windows 2000 Windows Me Windows XP Windows Vista windows 7 Windows 8 Windows 8.1 Windows 10
Windows 3.1 Windows 95 Windows 98 Windows 2000 Windows Me Windows XP Windows Vista Windows 7 Windows 10
比較結果が以下のように表示されます。
大文字小文字が区別されていないのがわかります。(windows 7とWindows 7が同じになっている)
PS C:\Users\sakura> Compare-Object (Get-Content a.txt) (Get-Content b.txt) InputObject SideIndicator ----------- ------------- Windows 98 => Windows 8 <= Windows 8.1 <=
オブションで-CaseSensitiveを追加すれば大文字小文字が区別されます。
PS C:\Users\sakura> Compare-Object -CaseSensitive (Get-Content a.txt) (Get-Content b.txt) InputObject SideIndicator ----------- ------------- Windows 98 => Windows 7 => windows 7 <= Windows 8 <= Windows 8.1 <=
以上、Compare-Objectコマンドレットを使ったファイル比較方法でした。