Score:0

check MD5 checksums from md5 file in Windows

cn flag

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!

Score:0
es flag

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]"
    }
}
16shells avatar
cn flag
Doesn't that just provide the hash for <filename>? I was after the equivalent of ```md5sum --check <filename>``` where it confirms the list of hashes in 'filename' match the files in that directory.
ShabbaSkanks avatar
es flag
Edited after revising my original answer, hope this helps
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.