SOSysAdmin logo SOSysAdmin


How to get the hash of a file on Windows

flag Scope

Computing the hash of a file on a Windows machine.

construction How-to

To compute the hash of a file on Windows we can use the Get-FileHash cmdlet on PowerShell.
  1. Open a PowerShell
  2. Execute the following command:
  3. Get-FileHash C:\path\to\file.txt -Algorithm MD5 | Format-List
Where:
  • C:\path\to\file.txt is the path of the file you want to get hash from
  • MD5 is the cryptographic hash function used for computing the hash value of the file. It can be one of those:
    • SHA1
    • SHA256
    • SHA386
    • SHA512
    • MD5
  • You will get the hash in a format like this:
  • 
                        Algorithm : MD5
                        Hash      : D41D8CD98F00B204E9800998ECF8427E
                        Path      : C:\path\to\file.txt
                    
    In this case the output is pretty straightforward. Here you can see that the MD5 hash of the file file.txt> is D41D8CD98F00B204E9800998ECF8427E (which is the hash for an empty file).


school Further considerations

  • If the -Algorithm parameter is omitted or it has no value specified, the default algorithm used will be SHA256.
  • You can read more about the Get-FileHash cmdlet on the Microsoft official documentation




Article ID: SYS-WIN-0006