Hash File comparison is a good thing to do, to make sure that file in transit, transferred, downloaded, or copied over is not corrupted or has been altered or modified.
PowerShell has a built-in module to do this that makes life easier and an easy task to do.
Here's an example code snippet to do this:
#Path location of the file
$file="C:\Users\User1\Downloads\Win10_22H2_EnglishInternational_x64.iso"
# Get the file hash
$hashSrc = Get-FileHash $file -Algorithm "SHA256"
write-output $hashSrc
#copy the Hash file
$Display_hash_only = $hashSrc | Select-Object -Property Hash | ft -HideTableHeaders
Write-Output $Display_hash_only
Output of the write-output $hashSrc command, will show the Algorithm used, the Hash of the file and path location of the file.
Algorithm : SHA256
Hash: AC5522F9DB9F4F432A1AADE69FEF268C8C0B5FD3F22D3A6987719752F8A7108
Path : C:\Users\User1\Downloads\Win10_22H2_EnglishInternational_x64.iso
After getting the Hash File run this code snippet below to compare the string. Compare the original Hash file and the output of the Hash file from above script.
$source_hash_file = "3AC5522F9DB9F4F432A1AADE69FEF268C8C0B5FD3F22D3A6987719752F8A7108"
$to_compare_hash_file = "3AC5522F9DB9F4F432A1AADE69FEF268C8C0B5FD3F22D3A6987719752F8A7108"
#compare hash file ignore case
$check = $to_compare_hash_file -eq $source_hash_file
Write-Output $check
#Compare if file hash matches
if ($check -eq "True") {
Write-Output "File Hash Matches"
} else{
Write-Output "File Hash does not Match"
}
Cheers! Take care. Till next Time.
Stay safe! and Keep things up!
Do ASAP, Always Say A Prayer...
Practice O.T.G. = Obedience To God
Make time for Prayer and Meditation.
================================
Free Android Apps:
Click links below to find out more:
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
Divine Mercy Chaplet Guide (A Powerful prayer) BFF = Be Filled Faith:
Comments
Post a Comment