My latest use of the .net / ActiveXPoSH dll... MD5 and SHA1 Checksum/Hash

Borrowed code from: http://www.tinyint.com/index.php/2011/09/14/get-an-md5-or-sha1-checksum-with-powershell/

break on
$RC=setoption("NoVarsInStrings","on")
$RC=setoption("NoMacrosInStrings","on")
$RC=setoption("WrapATEOL","on")
 
? GetCheckSum(@scriptdir + "\ActiveXPoSH.exe","MD5") ? GetCheckSum(@scriptdir + "\ActiveXPoSH.exe","SHA1")

Function GetCheckSum($file, $algorithm, optional $PSObject) if $PSobject="" $PSObject=CreateObject("SAPIEN.ActiveXPoSH") endif if $PSObject.init(not 0) if exist($file) $PSObject.execute('$fs = new-object System.IO.FileStream "' + $file + '", "Open"') $PSObject.execute('$algo = [type]"System.Security.Cryptography.' + $Algorithm + '"') $PSObject.execute('$crypto = $algo::Create()') $PSobject.execute('$hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "")') $PSObject.execute('$fs.Close()') $GetChecksum=$PSObject.getvalue('$hash') else exit 2 endif endif endfunction