How to Get a file’s MD5 checksum

By FoxLearn 3/20/2025 2:46:23 AM   44
To retrieve a file’s SHA256 checksum, you can use the Get-FileHash cmdlet. This feature has been available since PowerShell v4.
$checksum = (Get-FileHash -Algorithm SHA256 -Path C:\Documents\ImportantReport.pdf).Hash

In this case, the SHA256 checksum for the file is 9A0364B9E99BB480DD25E1F0284C8555.

If Get-FileHash is unavailable: Get-FileHash was introduced in PowerShell v4. If you're using an older version of PowerShell, you'll get the following error when trying to run the command:

Get-FileHash is not recognized as the name of a cmdlet, function, script file, or operable program.

You have two options: either upgrade PowerShell or use .NET's built-in functionality.

Option 1 - Use SHA256Managed to Get the SHA256 Checksum

If you can't or don't want to upgrade PowerShell, you can use .NET to get the SHA256 checksum like this:

$sha256 = New-Object -TypeName System.Security.Cryptography.SHA256Managed
$checksumBytes = $sha256.ComputeHash([System.IO.File]::ReadAllBytes("C:\Documents\ImportantReport.pdf"))
$checksum = [System.BitConverter]::ToString($checksumBytes).Replace("-", "")
$checksum

This will return the checksum: 9A0364B9E99BB480DD25E1F0284C8555.

Option 2 - Install PowerShell v4 or Above to Use Get-FileHash

If you're unsure what version of PowerShell you're using, you can check by running:

$PSVersionTable.PSVersion

For example, if you're using PowerShell v5.1, the output will look like this:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      18362  1171

If you're using a version older than v4, this command might not return anything at all, indicating it's time to upgrade.

After upgrading, you'll be able to use Get-FileHash to get the file checksum, like this:

$checksum = (Get-FileHash -Algorithm SHA256 -Path C:\Documents\ImportantReport.pdf).Hash