{"id":3634,"date":"2023-01-09T17:04:29","date_gmt":"2023-01-09T17:04:29","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=3634"},"modified":"2023-01-09T17:04:29","modified_gmt":"2023-01-09T17:04:29","slug":"cheeky-powershell-hash-script","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=3634","title":{"rendered":"Cheeky PowerShell Hash Script"},"content":{"rendered":"\n<p>If you want to check the (MD5\/SHA) hash of a file you can do this on Microsoft Windows with &#8220;Get-FileHash&#8221; within PowerShell.<\/p>\n\n\n\n<p>Here is a simple script to take a File, the Hash Algorithm Type and Expected Hash for the file to compare, it hashes the file and then compares it with the expected hash for the file, if it matches or not it reports this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>param($FileName,$AlgoType,$CompareHash)\r\n\r\n$hash = Get-FileHash $Filename -algorithm $AlgoType\r\n\r\n$InputHash = $hash.hash\r\n\r\nWrite-Host \"Input Filename:\" $FileName\r\nWrite-Host \"Input File Hash:\" $InputHash.ToLower() \" Expected Hash:\" $CompareHash\" = \" -NoNewline\r\n\r\nif ($InputHash -eq $CompareHash) {\r\n    Write-Host \"Hash Matches!\" -ForegroundColor Green\r\n} else {\r\n    Write-Host \"No Hash Match!\" -ForegroundColor Red\r\n}<\/code><\/pre>\n\n\n\n<p>For example, i&#8217;ve downloaded an XOS image for an Extreme Networks switch, if we run the following with the expected hash:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\\md5sum.ps1 -FileName '.\\summitX-22.7.5.1-patch1-3.xos' -AlgoType MD5 -CompareHash 34600b5ce116c26841ce8537d2ded620\r<\/code><\/pre>\n\n\n\n<p>We get the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Input Filename: .\\summitX-22.7.5.1-patch1-3.xos\r\nInput File Hash: 34600b5ce116c26841ce8537d2ded620  Expected Hash: 34600b5ce116c26841ce8537d2ded620 = Hash Matches!<\/code><\/pre>\n\n\n\n<p>If the file does not hash to the expected value we get:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Input Filename: .\\summitX-22.7.5.1 (1).xos\r\nInput File Hash: d35b34b993f9c5e91aaa83d547d13a11  Expected Hash: 34600b5ce116c26841ce8537d2ded620 = No Hash Match!<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you want to check the (MD5\/SHA) hash of a file you can do this on Microsoft Windows with &#8220;Get-FileHash&#8221; within PowerShell. Here is a simple script to take a File, the Hash Algorithm Type and Expected Hash for the file to compare, it hashes the file and then compares it with the expected hash &#8230; <a title=\"Cheeky PowerShell Hash Script\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=3634\" aria-label=\"Read more about Cheeky PowerShell Hash Script\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-3634","post","type-post","status-publish","format-standard","hentry","category-random"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3634"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3634\/revisions"}],"predecessor-version":[{"id":3635,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3634\/revisions\/3635"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}