Public/Test-OriAzBopModuleComplete.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.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

}