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
 
.PARAMETER SeachMask
    The seach mask to get tag with MD5
 
 
.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,

        [Parameter(Mandatory = $False, HelpMessage = "The seach mask to get tag with MD5")]
        [String] $SeachMask = 'MD5_v3-*'
    )
    $ErrorActionPreference = 'Stop'
    Write-Verbose "-- Get-OriAzBopModuleMd5FromTag --"
    Write-Verbose "SeachMask: $SeachMask"

    [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
            [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

}