1
0

Verify-File.ps1 726 B

123456789101112131415161718
  1. param([String]$filename="", [Int32]$filesize=0, [String]$hashvalue="", [String]$hashname="SHA512")
  2. Function Get-FileHashWin7([String] $FileName, $HashName) {
  3. $FileStream = New-Object System.IO.FileStream($FileName,[System.IO.FileMode]::Open)
  4. $StringBuilder = New-Object System.Text.StringBuilder
  5. [System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash($FileStream)|%{[Void]$StringBuilder.Append($_.ToString("x2"))}
  6. $FileStream.Close()
  7. $StringBuilder.ToString()
  8. }
  9. Write-Output "Verify " $filename
  10. if ((Get-Item $filename).length -ne $filesize) {
  11. Write-Output "Failed " $filename
  12. exit 1
  13. }
  14. if ((Get-FileHashWin7 $filename $hashname) -ne $hashvalue) {
  15. Write-Output "Failed " $filename
  16. exit 1
  17. }
  18. exit 0