Lets say that I need to verify the md5 hash of a file against the hash provided by the website.
I use certutil -hashfile .\amazon-corretto-11.0.10.9.1-windows-x64.msi md5
or Get-FileHash -Path .\amazon-corretto-11.0.10.9.1-windows-x64.msi -Algorithm md5
in powershell to get the hash, then I look at the hash from the download website, and compare them letter by letter. Is there a way to let the command line do the comparison?
I tried certutil -hashfile .\amazon-corretto-11.0.10.9.1-windows-x64.msi md5 | echo == "website_hash"
, but it didn't work.
Solutions in command line and powershell are both welcomed.
Continuing from my comment. Try this:
Get-FileHash -Path 'D:\temp\book1.txt' -Algorithm MD5 |
Format-Table -AutoSize
# Results
<#
Algorithm Hash Path
--------- ---- ----
MD5 D572724F26BD600773F708AB264BE45B D:\temp\book1.txt
#>
$CompareObjectSplat = @{
DifferenceObject = (Get-FileHash -Path 'D:\temp\book1.txt' -Algorithm MD5).Hash
ReferenceObject = (Get-FileHash -Path 'D:\temp\book1.txt' -Algorithm MD5).Hash
}
Compare-Object @compareObjectSplat -IncludeEqual
# Results
<#
InputObject SideIndicator
----------- -------------
D572724F26BD600773F708AB264BE45B ==
#>
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-FileHash).Parameters
(Get-Command -Name Get-FileHash).Parameters.Keys
Get-help -Name Get-FileHash -Examples
Get-help -Name Get-FileHash -Full
Get-help -Name Get-FileHash -Online
(Get-Command -Name Compare-Object).Parameters
(Get-Command -Name Compare-Object).Parameters.Keys
Get-help -Name Compare-Object -Examples
Get-help -Name Compare-Object -Full
Get-help -Name Compare-Object -Online
Tagging on to this as per mklement0's helpful response to you and your follow-up query.
# Command line - executable
(certutil -hashfile 'D:\temp\book1.txt' md5)
# Results
<#
MD5 hash of D:\temp\book1.txt:
d572724f26bd600773f708ab264be45b
CertUtil: -hashfile command completed successfully.
#>
(certutil -hashfile 'D:\temp\book1.txt' md5)[1] -eq (certutil -hashfile 'D:\temp\book1.txt' md5)[1]
# Results
<#
True
#>