Skip to content

Instantly share code, notes, and snippets.

@andrematias
Last active April 29, 2021 17:41
Show Gist options
  • Save andrematias/bc5e900e3571d29236032288dae81c23 to your computer and use it in GitHub Desktop.
Save andrematias/bc5e900e3571d29236032288dae81c23 to your computer and use it in GitHub Desktop.
Um script basico para gerar um md5 de arquivos e compara-los
Param (
$FirstFile = $(throw "Um primeiro arquivo eh requerido"),
$SecondFile = $(throw "Um segundo arquivo eh requerido")
)
function md5hash($path)
{
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$file = [System.IO.File]::Open($path,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
try {
Return [System.BitConverter]::ToString($md5.ComputeHash($file))
} finally {
$file.Dispose()
}
}
$a = md5hash($FirstFile)
$b = md5hash($SecondFile)
If ($a -eq $b)
{
Write-Host 'OK'
}
Else
{
Write-Host 'NOK'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment