Hash Checker On One Line by Joel Bennett 34 months ago
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/988"></script>download | new post
Check and md5 or sha1 hash in a “single line” of PowerShell.
- # to make it readable, I've wrapped the lines, but you can remove all the line breaks:
- &{
- PARAM($FileName,$HashFileName)
- ((Get-Content $HashFileName) -match $FileName)[0].split(" ")[0] -eq
- [string]::Join("", (
- [Security.Cryptography.HashAlgorithm]::Create(
- ([IO.Path]::GetExtension($HashFileName).Substring(1).ToUpper())
- ).ComputeHash(
- [IO.File]::ReadAllBytes( (Convert-Path $FileName)
- )
- ) | ForEach { "{0:x2}" -f $_ }))
- # Note that the last line here includes the PARAMETERS: FileName and HashFileName
- } npp.5.3.1.Installer.exe npp.5.3.1.release.md5
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository