-
Notifications
You must be signed in to change notification settings - Fork 0
/
sumcompare.ps1
39 lines (37 loc) · 1.08 KB
/
sumcompare.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.SYNOPSIS
Check if checksum is valid
.DESCRIPTION
.NOTES
This PowerShell script compare sha256sum.
You need to specify file as first argument,
and copy checksum for reference to clipboard.
.LINK
https://github.com/adambiro1/winbin
https://github.com/adrianbiro/winbin
#>
param([string]$File)
if($File) {
if (-not (Test-Path -Path $File -PathType Leaf)){
"$File does not exist."
exit
}
$checksum = Get-Clipboard
$valid = foreach($i in [char]'A'..[char]'F' && 0..9) {$i}
$ascii = foreach($i in 33..126) {"$([char]$i)"}
foreach($i in $ascii) {
if($valid -contains $i) { continue }
if($checksum.ToUpper().ToCharArray() -contains $i) {
"Checksum in clipboard is not valid"
exit
}
}
$isoHash = Get-FileHash $File -Algorithm sha256
if ($isoHash.Hash -eq $checksum.ToUpper()) {
"Checksum is valid."
} else {
"Checksum is not valid"
}
} else {
"Usage:`n`t{0} <file>" -f $MyInvocation.MyCommand.Name
}