Powershell support the following hashing algorithm:
- SHA1
- SHA256
- SHA384
- SHA512
- MD5
I created simple script that you can add to your powershell $PROFILE
function Get-FileChecksum {
param (
[string]$FilePath,
[string]$Algorithm = "MD5",
[switch]$WriteToFile
)
if (-not (Test-Path -Path $FilePath -PathType Leaf)) {
Write-Error "File not found: $FilePath"
return
}
$hash = Get-FileHash -Path $FilePath -Algorithm $Algorithm | Select-Object -ExpandProperty Hash
if ($WriteToFile) {
$checksumFileName = "$FilePath.$Algorithm"
$hash | Set-Content -Path $checksumFileName -Force
Write-Output "Checksum written to $checksumFileName"
} else {
Write-Output $hash
}
}
- Calculate checksum with default algorithm set (MD5) and display it:
Get-FileChecksum -FilePath "C:\Path\To\YourInstaller.exe"
- Calculate SHA-256 checksum and write it to a file:
Get-FileChecksum -FilePath "C:\Path\To\YourInstaller.exe" -Algorithm SHA256 -WriteToFile
This will write the checksum to a file with the format "YourInstaller.exe.SHA256" in the same directory as the installer.