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)]
        [String]$RequiredVersion,

        [Parameter(Mandatory=$False)]
        [Switch]$Force,

        [Parameter(Mandatory=$False)]
        [Switch]$DisableNameChecking,

        [Parameter(Mandatory=$False)]
        [ValidateSet('AllUsers','CurrentUser','VirtualEnv')]
        [String]$Scope="VirtualEnv"
    )


    # Get Dict of parameters
    $ModuleParams =  Get-FunctionParameters

    foreach ($ModuleName in $Name) {
        Try {
            if($Scope -eq 'VirtualEnv') {
                if($VirtualenvFolder){

                    # Tricks to avoid error on direct import in module
                    if((Test-Path $ModuleName) -eq $False) {
                        $ModuleParams['Name'] = (Get-ModuleManifest -Path $VirtualenvFolder -Name $ModuleName)
                    }

                    # Remove Scope To avoid error on Save-Module
                    $ModuleParams.Remove("Scope")
                    Microsoft.PowerShell.Core\Import-Module @ModuleParams
                } else {
                    Write-Error "Virtualenv has not been Enabled, please run Enable-VirtualEnv !"
                }
            } else {
                Microsoft.PowerShell.Core\Import-Module @ModuleParams
            }
        } Catch {
            Write-Error "Unable to import $ModuleName Module : $_"
        }
    }
}