{"id":63,"date":"2017-06-18T15:20:59","date_gmt":"2017-06-18T19:20:59","guid":{"rendered":"http:\/\/ziviz.us\/WP\/?p=63"},"modified":"2017-06-18T15:20:59","modified_gmt":"2017-06-18T19:20:59","slug":"hashcompare","status":"publish","type":"post","link":"https:\/\/www.ziviz.net\/WP\/2017\/06\/18\/hashcompare\/","title":{"rendered":"HashCompare"},"content":{"rendered":"<p style=\"text-align: center;\"><em>Code Release<\/em><\/p>\n<p>HashCompare compares a file with a known MD5 hash and returns the output in an SCCM compatible manner. To understand more about why this script exits as it does, you should read <a href=\"http:\/\/technet.microsoft.com\/en-au\/library\/989dfb1d-a003-4200-817d-f917d8ae096b#BKMK_Step4\">&#8220;To use a custom script to determine the presence of a deployment type&#8221;<\/a> (Under step 4) on technet.<\/p>\n<h2>Usage<\/h2>\n<h3>Configuration<\/h3>\n<p>The script is fairly simple. You only need to configure the top 2 lines. First set $FilePath to the location of the pre-existing file. Then set $ExpectedHash to the MD5 hash of the deployed file. You can get the MD5 hash from powershell using Get-Hash in Powershell 4.0 or, if you are not up to 4.0, by using this <a href=\"http:\/\/ziviz.us\/WP\/2017\/06\/18\/get-hash\/\">Get-Hash<\/a>.<\/p>\n<h3>General Usage<\/h3>\n<p>Inside of a powershell console enter the following:<\/p>\n<pre><code style=\"powershell\">&\"<Path to script>\"<\/code><\/pre>\n<p>Example:<\/p>\n<pre><code style=\"powershell\">&\"C:\\Scripts\\HashDetect.ps1\"<\/code><\/pre>\n<h3>SCCM Usage<\/h3>\n<p>After configuration, import the script as a new Detection Method for your deployment.<\/p>\n<h2>Script<\/h2>\n<pre><code>\r\n$FilePath = \"C:\\ProgramData\\MyApp\\MySettings.xml\"\r\n$ExpectedHash = \"00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00\"\r\n\r\nif (-not (Test-Path $FilePath))\r\n{\r\n    #File path not found. Not installed.\r\n    exit 0\r\n}\r\n\r\ntry\r\n{\r\n    $FileStream = New-Object IO.FileStream $FilePath, \"Open\"\r\n    $MD5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider\r\n    $Hash = [System.BitConverter]::ToString($MD5.ComputeHash($FileStream))\r\n}\r\ncatch\r\n{\r\n    Write-Error $_.ToString()\r\n    exit 1\r\n}\r\n\r\n#Compare the hash with a known hash\r\nif ($Hash -eq $ExpectedHash)\r\n{\r\n    Write-Output \"Hash match. File already installed.\"\r\n    exit 0\r\n}\r\nelse\r\n{\r\n    #Hash MisMatch. Not installed\r\n    exit 0\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Code Release HashCompare compares a file with a known MD5 hash and returns the output in an SCCM compatible manner. To understand more about why this script exits as it does, you should read &#8220;To use a custom script to determine the presence of a deployment type&#8221; (Under step 4) on technet. Usage Configuration The &hellip; <a href=\"https:\/\/www.ziviz.net\/WP\/2017\/06\/18\/hashcompare\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;HashCompare&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,4,8,7],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-c-sharp","category-code-release","category-powershell","category-sccm","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":1,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/posts\/63\/revisions\/64"}],"wp:attachment":[{"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziviz.net\/WP\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}