How to get the Hash of a file with PowerShell

When downloading files from the internet, its important to be sure that the file hasn’t been modified in anyway. Certain websites will profile a ‘hash’ of the file either on the website, or sometimes in a separate text file that can also be downloaded.

Once the file has been downloaded to your workstation, you need to create your own hash of the file, then compare the two to make sure they match. If one tiny change has been made to the file, even an extra space somewhere, the hash will be completely different.

To get the hash of a file, you can use the script below. Copy the text into PowerShell_ISE and save it as Get-FileHash.ps1 (or something along those lines).

Parameters
-FilePath
This is a Mandatory parameter
This is the path to the file that you want to create the hash of.

-HashingAlgorithm
This is NOT mandatory, but if not specified, the default option of SHA256 will be used
This is the Algorithm used when encrypting your file to create the hash.
Valid options are MD5, SHA1, SHA256, SHA384 and SHA512.

Example Usage

Default options, just specifying a path to a file.

Specifying a different Hashing Algorithm.

Leave a Reply

Your email address will not be published. Required fields are marked *