Public/Import-Module.ps1
Function Import-Module { <# .SYNOPSIS Warper to install a module on your VirtualEnv .PARAMETER Name Specifies an array of names of modules to install. .PARAMETER RequiredVersion Specifies the exact version number of the module to install. .PARAMETER Force Forces the command to run without asking for user confirmation. .PARAMETER Scope Specifies the installation scope of the module. .EXAMPLE Install-Module -Name Pester Install-Module -Name Pester -Force Install-Module -Name Pester -Scope CurrentUser .NOTES Version: 1.0.0 Author: Thomas ILLIET Creation Date: 21/07/2018 #> Param( [Parameter(Mandatory=$True)] [String[]]$Name, [Parameter(Mandatory=$False)] [Version]$RequiredVersion, [Parameter(Mandatory=$False)] [Switch]$Force, [Parameter(Mandatory=$False)] [Switch]$DisableNameChecking, [Parameter(Mandatory=$False)] [Switch]$PassThru ) # Get Dict of parameters $ModuleParams = Get-FunctionParameters foreach ($ModuleName in $Name) { Try { if(Test-Path -Path $ModuleName) { Microsoft.PowerShell.Core\Import-Module @ModuleParams -Global } else { if($VirtualenvFolder){ $ModuleParams['Name'] = Get-ModuleManifest -Path $VirtualenvFolder -Name $ModuleName Microsoft.PowerShell.Core\Import-Module @ModuleParams -Global } else { Write-Error "Virtualenv has not been Enabled, please run Enable-VirtualEnv !" } } } Catch { Write-Error "Unable to import $ModuleName Module : $_" } } } |