Private/Get-OriAzBopVersionParamHelper.ps1
<#
.SYNOPSIS Get module into Version param structure .PARAMETER Module Informations about required module .EXAMPLE Get-OriAzBopVersionParamHelper ` -Module @{'ModuleA',@{ModuleName='ModuleB';Guid=123;MaximumVersion='1.0.10';ModuleVersion='1.0.3';Version='1.0.2';PreRelease='pre06';AllowPrerelease='1'}} #> function Get-OriAzBopVersionParamHelper { [CmdLetBinding()] [OutputType([Hashtable])] param ( [Parameter(Mandatory = $true, HelpMessage = "Informations about required module")] $Module ) $ErrorActionPreference = 'Stop' Write-Verbose '-- begin - Get-OriAzBopVersionParamHelper --' Write-Debug "Module: $(ConvertTo-Json $Module)" # There can be in RequiredModules string or in ModuleVersion type # See possible parameters for parse # https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.modulespecification?view=pscore-6.2.0#properties [Hashtable] $toReturn = @{} if ('System.String' -eq $Module.getType().fullname) { $toReturn += @{Name = $Module } } else { # The type of $Module is most likely ModuleSpecification represent by HashTable at the moment. $toReturn += @{Name = $Module.ModuleName } if (![string]::IsNullOrEmpty($Module.Guid)) { $toReturn += @{Guid = $Module.Guid } } if (![string]::IsNullOrEmpty($Module.MaximumVersion)) { $toReturn += @{MaximumVersion = $Module.MaximumVersion } } if (![string]::IsNullOrEmpty($Module.ModuleVersion)) { # Only when is set RequiredVersion we do need add Prefix into Import-Module paramters $toReturn += @{RequiredVersion = $Module.ModuleVersion } } if (![string]::IsNullOrEmpty($Module.Version)) { $toReturn += @{Version = $Module.Version } } if (![string]::IsNullOrEmpty($Module.PreRelease)) { $toReturn += @{PreRelease = $Module.PreRelease } } if (![string]::IsNullOrEmpty($Module.AllowPrerelease)) { $toReturn += @{AllowPrerelease = $Module.AllowPrerelease } } } Write-Debug (ConvertTo-Json -InputObject $toReturn) Write-Verbose '-- End of Get-OriAzBopVersionParamHelper --' return $toReturn } |