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 -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 } } [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 -Message ("[ END: {0} ]" -f $Local:MyInvocation.MyCommand.Name) return $RequiredMd5 } |