Create SHA-256 Hash for File in PowerShell

The following commands allow you to create the SHA-256 hash for a file, in Base 64 format, in PowerShell. This can be compared to the hash stored by Foray ADAMS® for a file, less the “SHA256” prefix.

PowerShell - all versions

[System.Convert]::ToBase64String([byte[]] -split ((Get-FileHash "<FILE_PATH>").Hash -replace '..', '0x$& '))

Example:

[System.Convert]::ToBase64String([byte[]] -split ((Get-FileHash "C:\Temp\MyFile.txt").Hash -replace '..', '0x$& '))

 

PowerShell 7.1+

[System.Convert]::ToBase64String([System.Convert]::FromHexString((Get-FileHash "<FILE_PATH>").Hash))

Example:

 

Sample Output

YvPeMc0vFBGrP5v/KIrXAx6/qbR5WiMmSpt5YUOrbIo=

 

© 2023 Foray, LLC - All Rights Reserved