Advertisement
adilima

Verify MD5 Using Power Shell

Nov 19th, 2017
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # This script needs exactly 1 argument to search for any MHL files
  3. # thus, only works for a project that export MHL files
  4. # If we want to use it in any other projects, then we have to write different script
  5.  
  6. param($arg1)
  7.  
  8. if (!$arg1) {
  9.     Write-Host "You have to give me a directory name to search for the MHL files"
  10.     return
  11. }
  12.  
  13. Write-Host "Searching for MHL files in:" $arg1
  14.  
  15. $mhl_list = Get-ChildItem -Path $arg1\*.mhl -Recurse -File
  16. $currentDirectory = $PWD
  17.  
  18. foreach ($mhl_file in $mhl_list) {
  19.      
  20.     # We will walk into each MHL files found in the directory
  21.     Write-Host "Verifying:" $mhl_file
  22.     [xml]$xmlObj = Get-Content -Path $mhl_file
  23.     if (!$xmlObj) {
  24.         write-host "unexpected Null XML Object:" $mhl_file
  25.         continue
  26.     }
  27.  
  28.     # We'll have to step into this MHL file folder, in order to get the files correctly
  29.     write-host "Got MHL:" $mhl_file " from directory:" $mhl_file.directory
  30.     cd $mhl_file.directory
  31.  
  32.     # Now we will walk into each items refer to by this MHL
  33.     foreach ($entry in $xmlObj.hashlist.hash) {
  34.         # skip the creator, etc
  35.         $md5 = Get-FileHash -Path $entry.File -Algorithm MD5
  36.         if ($md5.Hash -ne $entry.md5) {
  37.             # Complain, loudly...
  38.             write-host "HASH FAILED:" $md5.Path " expecting:" $entry.md5 " got:" $md5.Hash
  39.         }
  40.         else {
  41.             write-host $entry.File $md5.Hash "OK"
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement