Skip to content

Test‑FileHash

viscalyxbot edited this page Feb 28, 2025 · 1 revision

SYNOPSIS

Tests the hash of a file against an expected hash value.

SYNTAX

Test-FileHash [-Path] <String> [-Algorithm] <String> [-ExpectedHash] <String>
 [<CommonParameters>]

DESCRIPTION

This function calculates the hash of a file using a specified algorithm and compares it to an expected hash value. It returns $true if the calculated hash matches the expected hash, and $false otherwise.

EXAMPLES

EXAMPLE 1

Test-FileHash -Path "C:\example.txt" -Algorithm "SHA256" -ExpectedHash "e5b7e987e069f57439dfe8341f942f142e924a3a344b8941466011c5049a0855"

Returns $true if the SHA256 hash of C:\example.txt matches the expected hash.

PARAMETERS

-Algorithm

The hashing algorithm to use (SHA1, SHA256, SHA384, SHA512, or MD5).

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpectedHash

The expected hash value to compare against.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Path

The path to the file to be hashed.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

RELATED LINKS

Clone this wiki locally