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