Skip to main content This browser is no longer supported. Show Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Get-FileHash
Computes the hash value for a file by using a specified hash algorithm. In this articleSyntax
DescriptionThe The purpose of hash values is to provide a cryptographically-secure way to verify that the contents of a file have not been changed. While some hash algorithms, including MD5 and SHA1, are no longer considered secure against attack, the goal of a secure hash algorithm is to render it impossible to change the contents of a file -- either by accident, or by malicious or unauthorized attempt -- and maintain the same hash value. You can also use hash values to determine if two different files have exactly the same content. If the hash values of two files are identical, the contents of the files are also identical. By default, the ExamplesExample 1: Compute the hash value for a fileThis example uses the
Example 2: Compute the hash value for an ISO fileThis example uses the
Example 3: Compute the hash value of a streamFor this example, we get are using System.Net.WebClient to download a package from the Powershell release page. The release page also documents the SHA256 hash of each package file. We can compare the
published hash value with the one we calculate with
Example 4: Compute the hash of a stringPowerShell does not provide a cmdlet to compute the hash of a string. However, you can write a string to a stream and use the InputStream parameter of
ParametersSpecifies the cryptographic hash function to use for computing the hash value of the contents of the specified file or stream. A cryptographic hash function has the property that it is infeasible to find two different files with the same hash value. Hash functions are commonly used with digital signatures and for data integrity. The acceptable values for this parameter are:
If no value is specified, or if the parameter is omitted, the default value is SHA256. For security reasons, MD5 and SHA1, which are no longer considered secure, should only be used for simple change validation, and should not be used to generate hash values for files that require protection from attack or tampering.
Specifies the input stream.
Specifies the path to a file. Unlike the Path parameter, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose the path in single quotation marks. Single quotation marks instruct PowerShell not to interpret characters as escape sequences.
Specifies the path to one or more files as an array. Wildcard characters are permitted.
InputsString You can pipe a string to the OutputsMicrosoft.Powershell.Utility.FileHash
FeedbackSubmit and view feedback for |