Verify File Hash with PowerShell
You download a very large file or a very sensitive file, do you trust it? Plenty of download providers provide a file hash which you can compare to validate the file downloaded, or you can create a file has yourself. The following deals with validating the downloaded/copied file.
The following script will validate a file hash against a provided known hash and algorithm, and display the results.
Modify $fileName with the name of the file you want to check.
Modify $originalHash with the hash provided.
Modify $algorithm with the correct original hash algorithm.
After you entered your values, saved the script as a .ps1 file, now you can run the script.
In order to up your game, this function provides the same as above but puts it in function format so you can call it whenever you want from within PowerShell or a script. To use this script, you need to save it, dot source it, then call it.
Save the script as a .ps1 file
Dot source the function. Open PowerShell and run . .\scriptName.ps1
Now you can call this function compare-FileHash from within PowerShell and provide the following parameters:
File is the path and name of the file you want to check.
Hash is the hash provided that you want to verify.
Algorithm is the algorithm used to create the original hash.
So an example command after dot sourcing this function could be: