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 "-- Test-OriAzBopModuleComplete --"
    Write-Verbose "Path: $Path"
    Write-Verbose "RequiredMd5: $RequiredMd5"

    [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 "-- End of Test-OriAzBopModuleComplete --"
    return $ToReturn

}