Public/Test-OriAzBopModuleComplete.ps1
<#
.SYNOPSIS Test if the Hash of Module is same like is required in the Manifest tag .DESCRIPTION Test if the Hash of Module is same like is required in the Manifest tag .PARAMETER Path The Path to the Module Manifest (.PSD1 file) .PARAMETER RequiredMd5 The required MD5 .EXAMPLE Test-OriAzBopModuleComplete ` -Path c:\temp\ ` -RequiredMd5 '5cfdcbf97b7a004f387c69d6b1dab25b' # Should return something like this: # 5cfdcbf97b7a004f387c69d6b1dab25b #> function Test-OriAzBopModuleComplete { [CmdLetBinding()] [Outputtype("Boolean")] param ( [Parameter(Mandatory = $True, HelpMessage = "The Path to folder to compute the Hash")] [ValidateScript({ Test-Path $_ })] [String] $Path, [Parameter(Mandatory = $True, HelpMessage = "The required MD5")] [String] $RequiredMd5 ) $ErrorActionPreference = 'Stop' Write-Verbose -Message ("[ START: {0}:{1} (v.{2}) ]" -f $Local:MyInvocation.MyCommand.Source, $Local:MyInvocation.MyCommand.Name, $Local:MyInvocation.MyCommand.Version) foreach ($arg in $PSBoundParameters.GetEnumerator()) { if ([string]::IsNullOrEmpty($arg.Value)) { Write-Debug -Message ("[null] {0}: {1}" -f $arg.Key, $arg.Value) -ErrorAction SilentlyContinue } else { Write-Debug -Message ("[{2}] {0}: {1}" -f $arg.Key, $arg.Value, $arg.Value.GetType().Name) -ErrorAction SilentlyContinue } } [bool] $ToReturn = $false [string] $CurrentMd5 = Get-OriAzBopFolderHash ` -Path (get-item $Path).Directory.FullName ` -ExcludePath (Split-Path $Path -leaf) ` -Verbose:$VerbosePreference ` -Debug:$DebugPreference Write-Debug "Current MD5 [$CurrentMd5] and required [$RequiredMd5] found in module." if ($CurrentMd5 -eq $RequiredMd5) { Write-Debug "MD5 [$CurrentMd5] and required [$RequiredMd5] is matching." $ToReturn = $true } else { Write-Debug "MD5 [$CurrentMd5] and required [$RequiredMd5] are different." $ToReturn = $false } Write-Verbose -Message ("[ END: {0} ]" -f $Local:MyInvocation.MyCommand.Name) return $ToReturn } |