Public/Wait-OriAzBopModuleComplete.ps1
<#
.SYNOPSIS Should return wait till the CRC of module is ok or MaxRetry is reched. .DESCRIPTION Should return wait till the CRC of module is ok or MaxRetry is reched. .PARAMETER Path Specifies the exact names of modules to install from the online gallery. The module name must match the module name in the repository. .PARAMETER SleepInSec Sleep time in sec between test if the module is ready to import. .PARAMETER MaxRetry Max retry while waiting to import module .EXAMPLE Wait-OriAzBopModuleComplete ` -Path c:\temp\ ` -SleepInSec 30 ` -MaxRetry 20 #> function Wait-OriAzBopModuleComplete { [CmdLetBinding()] param ( [Parameter(Mandatory = $True, HelpMessage = "The Path to folder to compute the Hash")] [ValidateScript( { Test-Path $_ })] [String] $Path, [Parameter(Mandatory = $False, HelpMessage = "Sleep time in sec between test if the module is ready to import.")] [int] $SleepInSec = 3, [Parameter(Mandatory = $False, HelpMessage = "Max retry")] [int] $MaxRetry = 20 ) $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 = Get-OriAzBopModuleMd5FromTag -Path $Path -Verbose:$VerbosePreference -Debug:$DebugPreference if ([string]::IsNullOrEmpty($RequiredMd5)) { Write-Debug "No MD5 found in module." } else { Write-Debug "the MD5 [$RequiredMd5] found in module." [int] $try = 1 While (-not(Test-OriAzBopModuleComplete -Path $Path -RequiredMd5 $RequiredMd5 -Verbose:$VerbosePreference -Debug:$DebugPreference)) { Write-Debug "Retry number [$try]. Max retry is [$MaxRetry]" if ($try -ge $MaxRetry) { throw "The module [$Path] is not complete based on MD5 in the module tag is expected [$RequiredMd5]. Max retry [$MaxRetry] reached." } Start-Sleep -Seconds $SleepInSec $try++ } } Write-Verbose -Message ("[ END: {0} ]" -f $Local:MyInvocation.MyCommand.Name) } |