Skip to content

Instantly share code, notes, and snippets.

@milnak
Last active November 22, 2023 17:52
Show Gist options
  • Save milnak/e5e98ecf50eff4a92dbb8e0213500626 to your computer and use it in GitHub Desktop.
Save milnak/e5e98ecf50eff4a92dbb8e0213500626 to your computer and use it in GitHub Desktop.
md5sum --check in PowerShell
$md5sum = Get-Content '.\test.md5' | Select-String -Pattern '^([0-9a-fA-F]+) ([ \*])(.+)' | ForEach-Object { $hash,$binary, $path = $_.Matches[0].Groups[1..3].Value; [PSCustomObject] @{Hash=$hash; Binary=[Bool]($binary -eq '*'); Path=$path } }
$md5sum | ForEach-Object { if ($_.Hash.ToLower() -eq (Get-FileHash $_.Path -Algorithm MD5 -ErrorAction SilentlyContinue -ErrorVariable HashError).Hash) { "$($_.Path): OK" } else { if ($HashError) { "$HashError`n$($_.Path): FAILED open or read" } else { "$($_.Path): FAILED" } } }
@milnak
Copy link
Author

milnak commented Oct 4, 2022

differences:

original md5sum has different error output, e.g.

e:\bin\md5sum.exe: ..\file.bin: No such file or directory

original reports summaries:

e:\bin\md5sum.exe: WARNING: 1 of 3 listed files could not be read

e:\bin\md5sum.exe: WARNING: 1 of 2 computed checksums did NOT match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment