Skip to content

Get-Md5

Prints the MD5 checksum 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 MD5

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

Specifies the file path to the file

An interactive directory of PowerShell scripts.