Saving result of CertUtil -hashfile to a variable and remove spaces of the hash

Use powershell command:

$(CertUtil -hashfile C:\TEMP\MyDataFile.img MD5)[1] -replace " ",""

I am totally late to this, but how about just using find to get rid of the unwanted lines:

 CertUtil -hashfile "path_to_file" MD5 | find /i /v "md5" | find /i /v "certutil"

Despite the answer above, typicall setlocal enabledelayedexpansion issue

@echo off
setlocal enabledelayedexpansion
set /a count=1 
for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile "ping.txt" MD5') do (
  if !count! equ 1 set "md5=%%a"
  set/a count+=1
)
set "md5=%md5: =%
echo %md5%
endlocal
exit/B