Private/Import-specModule2.ps1
|
function Import-specModule2 { <# .SYNOPSIS Imports a specific version of a PowerShell module. .DESCRIPTION Attempts to import a module with the required version using Import-Module. .PARAMETER Name The name of the module to import. .PARAMETER Version The required version of the module. .EXAMPLE Import-specModule2 -Name 'MyModule' -Version '1.0.0' .NOTES Author: owen.heaume Version: 1.0 - Initial release #> [cmdletbinding()] param ( [Parameter(Mandatory)] [string]$Name, [Parameter(Mandatory)] [string]$Version ) try { Import-Module -Name $Name -RequiredVersion $Version -Force -ea stop } catch { Write-Error ("Failed to import module '{0}' v{1}: {2}" -f $Name, $Version, $_.Exception.Message) } } |