PowerShell Genie

Get-FileHash

Use Get-FileHash to compute a cryptographic hash of a file, defaulting to SHA256.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Get-FileHash

Syntax

1PS> Get-FileHash [-Path] <String[]> [-Algorithm <String>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Get-FileHash [-Path] <String[]> [-Algorithm <String>] [<CommonParameters>]
  1. Stage 1Get-FileHash-Path -Algorithm

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Select Algorithm, Hash

    1PS> Get-FileHash 'C:\Scripts\Backup-Files.ps1' | Select-Object Algorithm, Hash
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Algorithm  Hash                                                              Path
    ---------  ----                                                              ----
    SHA256     2F8C9C2D9E428E5F3C8B0E8D66F8D8FA103A238A45A690C8D9B9239A0F849DB4  C:\Temp\file.zip

    Select first 3

    1PS> Get-FileHash 'C:\Scripts\*.ps1' | Select-Object -First 3 Hash, Path
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Algorithm  Hash                                                              Path
    ---------  ----                                                              ----
    SHA256     2F8C9C2D9E428E5F3C8B0E8D66F8D8FA103A238A45A690C8D9B9239A0F849DB4  C:\Temp\file.zip

    Get-FileHash -Algorithm MD5

    1PS> Get-FileHash 'C:\Scripts\Backup-Files.ps1' -Algorithm MD5 | Select-Object Algorithm, Hash
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Algorithm  Hash                                                              Path
    ---------  ----                                                              ----
    MD5        2F8C9C2D9E428E5F3C8B0E8D66F8D8FA103A238A45A690C8D9B9239A0F849DB4  C:\Temp\file.zip

    Parameters

    Parameter definitions:

    • -Path
    • -Algorithm

    Get-FileHash on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Get-FileHash when you need to compute a cryptographic hash of a file, defaulting to SHA256. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A mismatch may indicate a different version or changed bytes. Confirm the expected algorithm and obtain the reference digest from a trusted source before accepting the file. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Get-AuthenticodeSignature. Get-FileHash calculates a file digest; Get-AuthenticodeSignature examines its signature. A matching hash needs a trusted reference value and is not evidence of a trusted publisher by itself. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Get-FileHash reference on Microsoft Learn

    Recap

    Get-FileHash Use Get-FileHash to compute a cryptographic hash of a file, defaulting to SHA256.

    Next: Get-Acl
    Genie guideGet-FileHash

    Use Get-FileHash to compute a cryptographic hash of a file, defaulting to SHA256. The console below is pre-loaded — run it, then change a value and run it again.