Skip to content

Instantly share code, notes, and snippets.

@hube
Last active June 7, 2020 02:36
Show Gist options
  • Save hube/951e807cb9ebec4dda72e5ca3c0a0135 to your computer and use it in GitHub Desktop.
Save hube/951e807cb9ebec4dda72e5ca3c0a0135 to your computer and use it in GitHub Desktop.
Compare the files of two directories using content hashes
$referencePath = "a"
$differencePath = "b"
$lhs = Get-ChildItem -Recurse -File -Path $referencePath
$lhs_hashes = $lhs | Select-Object Name, FullName, Length, @{Name="Hash"; Expression={ Get-FileHash $_.FullName }}
$rhs = Get-ChildItem -Recurse -File -Path $differencePath
$rhs_hashes = $rhs | Select-Object Name, FullName, Length, @{Name="Hash"; Expression={ Get-FileHash $_.FullName }}
$diff = Compare-Object $lhs_hashes $rhs_hashes -property @("Name", "Hash")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment