From 93cc08e613fa667e60d7c5bfeff101100bba06a6 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 27 Apr 2015 11:55:14 -0500 Subject: [PATCH] Applying bf916fb5 fix to v2 --- v2/ansible/module_utils/powershell.ps1 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/v2/ansible/module_utils/powershell.ps1 b/v2/ansible/module_utils/powershell.ps1 index c097c69768..57d2c1b101 100644 --- a/v2/ansible/module_utils/powershell.ps1 +++ b/v2/ansible/module_utils/powershell.ps1 @@ -142,3 +142,25 @@ Function ConvertTo-Bool return } +# Helper function to calculate md5 of a file in a way which powershell 3 +# and above can handle: +Function Get-FileMd5($path) +{ + $hash = "" + If (Test-Path -PathType Leaf $path) + { + $sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider; + $fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read); + [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower(); + $fp.Dispose(); + } + ElseIf (Test-Path -PathType Container $path) + { + $hash= "3"; + } + Else + { + $hash = "1"; + } + return $hash +}