1

Hopefully a simple question, does a simple Windows command line equivalent to md5sum --check [files.md5] exist? Alternatively, something I can script as a batch file.

I can generate the hashes file fine, but it's the check at the destination, comparing with the md5 file that's proving tricky. Bonus points if it's possible to run in a batch file rather than PowerShell (need to try and create something relatively simple for a user to run routinely).

Many thanks!

1 Answers1

0

Powershell is your friend. You could run this with a CMD/BAT wrapper to just run the script for them

clear-host
$sourcemd5 = get-content C:\temp\cp053854.md5

cd C:\Temp foreach ($datarow in $sourcemd5){ # try this to replace mutli spaces with single. uses regex $datarow = $($datarow -replace '\s+', ' ') $dlhash = $null $currentFileHash = $null $currentFileName = $null #use the first (0) token found (hash value) $currentFileHash = ($datarow.Split(" "))[0] #use the second (1) token found (filename value) $currentFileName = ($datarow.Split(" "))[1] #$currentFileName check if has leading asterisk*. if ($currentFileName -match "*"){ #remove it $currentFileName = $currentFileName.Trim("*") }

# Generate an MD5 of the filesystem file
$dlhash = get-filehash $currentFileName -Algorithm MD5
#set the generated hash value as string for comparison to the text file.
[string]$dlhashstr = $dlhash.Hash
write-output "checking file                   [$currentfileName]"
write-output "downloaded file hash            [$dlhashstr]"
write-output "hash value should be            [$currentFileHash]"
#perform a case insensitive comparison if MD5file uses caps or not. 
if ($dlhashstr -eq $currentFileHash){
write-output "File hashes correctly match up  [$currentFileName]"
}else{
Write-Warning "MD5 checksum mismatch  [$currentFileName]"
}

}