Private/Get-VersionParamHelper.ps1
<#
.SYNOPSIS Get module into Version param structure .PARAMETER InstalledLocation Path to installed location of the module #> function Get-VersionParamHelper { [CmdLetBinding()] [OutputType([Hashtable])] param ( [Parameter(Mandatory = $true, HelpMessage = "Informations about required module")] $Module ) $ErrorActionPreference = 'Stop' Write-Verbose '-- begin - Get-VersionParamHelper --' 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.RequiredVersion)) { # Only when is set RequiredVersion we do need add Prefix into Import-Module paramters $toReturn += @{RequiredVersion = $Module.RequiredVersion } } if (![string]::IsNullOrEmpty($Module.Version)) { $toReturn += @{Version = $Module.Version } } if (![string]::IsNullOrEmpty($Module.AllowPrerelease)) { $toReturn += @{AllowPrerelease = $True } } } Write-Debug (ConvertTo-Json -InputObject $toReturn) return $toReturn Write-Verbose '-- end - Get-VersionParamHelper --' } |