loonison101
8/7/2015 - 2:06 AM

Check-Hash.ps1

# Function / CmdLet that compares the MD5 hash of a file to a expected hash passed in via an argument
# Put in powershell profile ($profile) if you want it as a global function, or put it into a module to be imported
function Check-Hash ($file, $expectedHash)
{
    $result = (Get-FileHash $file -Algorithm MD5).Hash.ToLower() -eq $expectedHash.Trim().ToLower()

    if ($result -eq $true) {
        Write-Host $result -ForegroundColor Green
    } else {
        Write-Host $result -ForegroundColor Red
    }
}

# How to use
# Check-Hash C:\users\User1\Downloads\VMware-converter-en-6.0.0-2716716.exe "f64589b50f416ebf5de547a402b091cb"