top of page
  • Writer's pictureChris Keim

Verify File Hash with PowerShell

Updated: Nov 2, 2020


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.


PowerShell Script

The following script will validate a file hash against a provided known hash and algorithm, and display the results.

  1. Modify $fileName with the name of the file you want to check.

  2. Modify $originalHash with the hash provided.

  3. Modify $algorithm with the correct original hash algorithm.

  4. After you entered your values, saved the script as a .ps1 file, now you can run the script.

PowerShell Function

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.

  1. Save the script as a .ps1 file

  2. Dot source the function. Open PowerShell and run . .\scriptName.ps1

  3. 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:

Have fun!

965 views0 comments
bottom of page