PoshCode Archive  Artifact [8d0e64bca0]

Artifact 8d0e64bca06cc9e2bcca870d8ca029de58d0a21775d1014fe1d3d1c45d14bf75:

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

# 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: 6209
# x-archived: 2016-03-18T21:54:14
# x-published: 2016-02-09T20:42: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