functions/Start-MineCraft.ps1

function Start-MineCraft {
    [cmdletBinding(DefaultParameterSetName="default")]
    param([string]$Name, [string]$Version, [switch]$NoPersist, [string]$MinecraftPath)
    $ErrorActionPreference = "Stop"

    $mcProfile = LoadProfile

    if(-not $Name) {
        if(-not $mcProfile.Name) {
            while(-not $Name) { $Name = Read-Host "Please enter your name (pay attention to capitalization!)" }
            $mcProfile.Name = $Name
        }
        else {
            $Name = $mcProfile.Name
            Write-Host "Using '$Name' from profile."
            Write-Host
        }
    }
    else { $mcProfile.Name = $Name }
    
    if(-not $Version) {
        if(-not $mcProfile.Version) {
            $versionList = GetMinecraftVersions
            while(-not $Version -or $version -notin $versionList) {
                Write-Host ("Available Versions: {0}" -f ($versionList -join ", "))
                $Version = Read-Host "Please enter the version you want to play"
            }
            $mcProfile.Version = $Version
        }
        else {
            $Version = $mcProfile.Version
            Write-Host "Using '$Version' from profile."
            Write-Host
        }
    }
    else { $mcProfile.Version = $Version }

    if(-not $MinecraftPath) {
        if(-not $mcProfile.Path) {
            $MinecraftPath = [CmlLib.Core.MinecraftPath]::new()
            $mcProfile.Path = $MinecraftPath
        }
        else {
            $MinecraftPath = $mcProfile.Path
            Write-Host "Using '$MinecraftPath' from profile."
            Write-Host
        }
    }
    else { $mcProfile.Path = $MinecraftPath }
    
    if(-not $NoPersist) { SaveProfile -MCProfile $mcProfile }
    
    #launch minecraft
    Write-Host "Getting Session..." -NoNewline
    $session = [CmlLib.Core.Auth.MSession]::GetOfflineSession($Name)
    Write-Host "Creating Launcher..." -NoNewline
    $launcher = [CmlLib.Core.CMLauncher]::new([CmlLib.Core.MinecraftPath]::new($MinecraftPath))
    $launchOption = [CmlLib.Core.MLaunchOption]@{Session = $session}
    Write-Host "Starting Process..."
    $launcher.CreateProcess("$version", $launchOption).Start() | Out-Null
    
    Write-Host "MineCraft may take a few seconds to launch, please be patient..."
    Write-Host
    (1..16) | ForEach-Object { Start-Sleep -Milliseconds 500; Write-Host "." -NoNewline }
}

Register-ArgumentCompleter -CommandName Start-MineCraft -ParameterName Version -ScriptBlock { GetMinecraftVersions }