PoshCode Archive  Artifact [2504242227]

Artifact 2504242227db492e30e8bfba15d699a748eb84d9447b118b9141d677227f8ff7:

  • File Hash-Checker-On-One-Line.ps1 — part of check-in [43450bf8b2] at 2018-06-10 14:27:53 on branch trunk — Check and md5 or sha1 hash in a “single line” of PowerShell. (user: Joel Bennett size: 910)

# encoding: ascii
# api: powershell
# title: Hash Checker On One Line
# description: Check and md5 or sha1 hash in a “single line” of PowerShell.
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 988
# x-archived: 2016-05-17T14:21:13
# x-published: 2009-04-01T11:55:00
#
#
# 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