Skip to content

Get-Sha256

Prints the SHA256 hash of a file

param([string]$path = "")

try {
	if ($path -eq "" ) { $path = Read-Host "Enter the file path" }
	if (-not(Test-Path $path -pathType leaf)) { throw "Invalid file path given: $path" }

	$result = Get-FileHash -path $path -algorithm SHA256

	"? SHA256 hash is $($result.Hash)"
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the local file path to the file

An interactive directory of PowerShell scripts.