Public/Get-OriAzBopModuleMd5FromTag.ps1

<#
.SYNOPSIS
    Get MD5 from the tag if exists
 
.DESCRIPTION
    Get MD5 from the tag if exists
 
.PARAMETER Path
    Path to the Module manifest .PSD1 file
 
 
.EXAMPLE
Get-OriAzBopModuleMd5FromTag `
-Path c:\temp\myModule.psd1
 
# Should return something like this when the tag MD5-5cfdcbf97b7a004f387c69d6b1dab25b is present:
# 5cfdcbf97b7a004f387c69d6b1dab25b
#>


function Get-OriAzBopModuleMd5FromTag {
    [CmdLetBinding()]
    [Outputtype("String")]
    param (
        [Parameter(Mandatory = $True, HelpMessage = "The Path to folder to compute the Hash")]
        [ValidateScript({Test-Path $_ })]
        [String] $Path
    )
    $ErrorActionPreference = 'Stop'
    Write-Verbose "-- Get-OriAzBopModuleMd5FromTag --"

    [string] $RequiredMd5 = ''
    $Manifest = Import-PowershellDataFile -LiteralPath $Path
    foreach ($onePrivateData in $Manifest.PrivateData) {
        foreach ($onePSData in $onePrivateData.PSData) {
            if([string]::IsNullOrEmpty($onePSData.Tags)) {
                [Object[]] $Tags = @()
            } else {
                [Object[]] $Tags = $onePSData.Tags 
            }
            
            # Get only tags releavant to this module
            $SeachMask = 'MD5-*'
            [String] $Md5Tag = $Tags |Where-Object {$_ -ilike $SeachMask} | Select-Object -First 1
            [string[]] $Md5TagmArrray = $Md5Tag -split '-', 2
            if (![string]::IsNullOrEmpty($Md5TagmArrray[0]) `
            -and ![string]::IsNullOrEmpty($Md5TagmArrray[1])) {
                $RequiredMd5 = $Md5TagmArrray[1]
            }
        }
    }

    Write-Verbose "-- End of Get-OriAzBopModuleMd5FromTag --"
    return $RequiredMd5

}