1 Set-Variable tempfile -option Constant -value "tempfile" 2 hash($path)3function hash($path) { 4 $fullPath = Resolve-Path $path 5 $hash = new-object -TypeName System.Security.Cryptography.SHA256CryptoServiceProvider 6 7 $contents = [IO.File]::ReadAllText($fullPath) -replace "`r`n?", "`n" 8 # create UTF-8 encoding without signature 9 $utf8 = New-Object System.Text.UTF8Encoding $false 10 # write the text back 11 [IO.File]::WriteAllText($tempfile, $contents, $utf8) 12 13 $file = [System.IO.File]::Open($tempfile,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read) 14 $result = [System.BitConverter]::ToString($hash.ComputeHash($file)) 15 $file.Dispose() 16 17 if (Test-Path $tempfile) { 18 Remove-Item $tempfile 19 } 20 21 return $result 22 } 23 main()24function main() { 25 $files = $(Get-ChildItem * | Where-Object { $_.Name -match '^[a-z2]*(_v)?[0-9]*$' } | select -ExpandProperty name) 26 27 foreach ($file in $files) { 28 $new = $(hash $file).replace("-","") 29 $new = $new.ToLower() 30 31 $old=$(Get-Content $file".shasum") 32 $old = $old.Substring(0, $old.IndexOf(" ")) 33 34 if ($new -eq $old) { 35 Write-Host $file "`tOK" 36 } else { 37 Write-Host $file "`tERROR" 38 } 39 } 40 } 41 42 main 43