Public/Initialize-Virtualenv.ps1

Function Initialize-Virtualenv(){
    <#
    .SYNOPSIS
        To enable Virtualenv on your PowerShell console
    .PARAMETER Name
        Indicates the name of your new Virtualenv
    .PARAMETER Path
        Specifies the absolute path of your new Virtualenv
    .EXAMPLE
        PS> Initialize-Virtualenv -Name 'venv'
        PS> Initialize-Virtualenv -Path 'c:\script\myproject\venv'
    .NOTES
        Version: 1.0.1
        Author: Thomas ILLIET
        Creation Date: 22/07/2018
    #>

    [CmdletBinding(DefaultParameterSetName='ByName')]
    Param(
        [Parameter(Mandatory = $False, ParameterSetName = 'ByName')]
        [string]$Name,

        [Parameter(Mandatory = $False, ParameterSetName = 'ByPath')]
        [string]$Path
    )

    Try {
        # Define Virtualenv Path
        switch ($PsCmdlet.ParameterSetName){
            "ByName" {
                if([string]::IsNullOrEmpty($Name)){
                    $VirtualenvPath  = Join-Path -Path (get-location) -ChildPath 'venv'
                } else {
                    $VirtualenvPath  = Join-Path -Path (get-location) -ChildPath $Name
                }
            }
            "ByPath" {
                $VirtualenvPath  = $Path
            }
        }

        # Create a new Virtualenv
        if((Test-Path $VirtualenvPath) -eq $False){
            New-Item -ItemType directory -Path $VirtualenvPath | Out-Null
        } else {
            Write-Warning "Virtual Environment has already exist !"
        }
    } Catch {
        Write-Error "Unable to create Powershell Virtualenv : $($_.Exception.Message)"
    }
}