Private/Get-ExternalDependenciesParamBasedOnTags.ps1
<#
.SYNOPSIS Get module into Version param structure .PARAMETER ModuleName Name of the module .PARAMETER Tags Array of module tags #> function Get-ExternalDependenciesParamBasedOnTags { [CmdLetBinding()] [OutputType([Hashtable])] param ( [Parameter(Mandatory = $true, HelpMessage = "Name of the module")] [string] $ModuleName, [Parameter(Mandatory = $true, HelpMessage = "Array of module tags")] [AllowEmptyCollection()] [String[]] $Tags ) $ErrorActionPreference = 'Stop' Write-Verbose '-- begin - Get-ExternalDependenciesParamBasedOnTags --' Write-Debug "ModuleName: $ModuleName" Write-Debug "Tags: $(ConvertTo-Json $Tags)" [Hashtable] $NewInstallParam = @{Name = $ModuleName} # Get only tags releavant to this module $SeachMask = 'ExternalModuleDependencies_{0}_*' -f $ModuleName [String[]] $relevantTags = $Tags |Where-Object {$_ -ilike $SeachMask} | Sort-Object -Unique # Get parameters relevant to the Module if($relevantTags.Count -gt 0) { $moduleInstallParam = $relevantTags.Substring(("ExternalModuleDependencies_{0}_" -f $ModuleName).Length) } # Try to parse each tag to get values for next processing foreach ($item in $moduleInstallParam) { [string[]] $paramArrray = $item -split '-', 2 if (![string]::IsNullOrEmpty($paramArrray[0])) { switch ($paramArrray[0]) { 'RequiredVersion' { $NewInstallParam += @{ RequiredVersion = [Version]$paramArrray[1]}; break} 'MaximumVersion' { $NewInstallParam += @{ MaximumVersion = [Version]$paramArrray[1]}; break} 'RequiredVersion' { $NewInstallParam += @{ RequiredVersion = [Version]$paramArrray[1]}; break} 'Version' { $NewInstallParam += @{ Version = [Version]$paramArrray[1]}; break} 'AllowPrerelease' { $NewInstallParam += @{ AllowPrerelease = [boolean]::Parse($paramArrray[1])}; break} 'Guid' { $NewInstallParam += @{ Guid = $paramArrray[1]}; break } 'Prerelease' { $NewInstallParam += @{ Prerelease = $paramArrray[1]}; break } Default { throw "Unknown tag [$item] relevant to the Module $ModuleName"} } } } Write-Debug (ConvertTo-Json -InputObject $NewInstallParam) Write-Verbose '-- End of Get-ExternalDependenciesParamBasedOnTags --' return $NewInstallParam } |