Skip to main content

How to Get File Hash in PowerShell

• 3 min read
powershell file hash sha256 security

To get file hash in PowerShell, you can use the Get-FileHash cmdlet. This command provides different hash algorithms such as SHA1, SHA256, SHA384 and MD5.

Get File Hash Using Get-FileHash in PowerShell

You can get file hash in PowerShell by using the Get-FileHash cmdlet. The Get-FileHash command uses the -Algorithm parameter to specify the algorithm to calculate the hash value of the specified file.

# specify the path to the file
$filePath = "C:\temp\log\system_log.txt"

# Get the hash of the file

$fileHash = Get-FileHash -Path $filePath -Algorithm SHA256

# Output the file hash
Write-Output $fileHash.Hash

In this PowerShell script, the $filePath variable stores the path to the file for which you want to calculate the hash.

The Get-FileHash cmdlet calculates the hash of the file specified by $filePath using the algorithm SHA256 and stores the result in the $fileHash variable.

Finally, we can output the hash value of the file using the Write-Output cmdlet.

After running the above script, PowerShell will output the hash value of the specified file.

Conclusion

I hope the above article on how to get the hash value of the file in PowerShell is helpful to you.


File Information & Properties

File Management Operations

Data Selection & Filtering

Date & Time Operations

Display & Output

Control Flow & Logic

Variables & Collections

Output & Export

File Content Operations

Functions & Automation

Storage & Disk Operations

Comprehensive Guides