Private/Test-GetModule.ps1
<#
.SYNOPSIS Checks, whether specified module is loaded. .PARAMETER Name Exact name of the mmodule .PARAMETER RequiredVersion Minimum required module version .EXAMPLE Test-GetModule -Name myModule -RequiredVersion 1.0.1 #> function Test-GetModule { [CmdLetBinding()] [OutputType([bool])] param ( [Parameter(Mandatory = $true, HelpMessage = "Exact name of the mmodule")] [string] $Name, [Parameter(Mandatory = $false, HelpMessage = "Minimum required module version")] [Version] $RequiredVersion ) $ErrorActionPreference = 'Stop' $module = Get-Module -Name $Name -ErrorAction SilentlyContinue if ([string]::IsNullOrEmpty($module) -or [string]::IsNullOrEmpty($module.Version)) { return $false } if ([string]::IsNullOrEmpty($RequiredVersion)) { return $true } if ([Version] $module.Version -ge $RequiredVersion) { return $true } else { return $false } } |