Note: Tested using PowerShell Version 4
You may want to check the file you’ve downloaded from the Internet hasn’t been changed and websites sometimes have the file hashes to verify this.
In the code below, copy the file hash from the website and paste it in after the ReferenceObject parameter, input the algorithm that was used to produce the hash after the Algorithm parameter and then input the Path to the downloaded file.
Compare-Object -ReferenceObject CopiedFileHash-DifferenceObject ((Get-FileHash -Algorithm AlgorithmUsed -Path \Path\Filename.extension).hash) -IncludeEqual
After downloading WinDirStat to my C:\Downloads directory, I can check the SHA1 hash by running the following command.
Compare-Object -ReferenceObject 6fa92dd2ca691c11dfbfc0a239e34369897a7fab -DifferenceObject ((Get-FileHash -Path C:\Downloads\windirstat1_1_2_setup.exe -Algorithm SHA1).hash) -IncludeEqual
The IncludeEqual parameter is optional. If you don’t use it and the objects match, PowerShell will return to the command prompt with no output displayed from running the command. The IncludeEqual parameter will display the InputObject, in this case the hash value and two equals signs to show that the objects (hashes in this case) match.
Hashes don’t match
If the hashes don’t match, the hash from the file will be displayed along with the hash that was pasted in. The <= shows the first compared object, in this case the pasted hash and the => shows the second compared object, the hash from the file.
For the screenshot below, I changed the end character of the pasted hash value to show what is displayed when the values don’t match.