functions/Connect-ZG.ps1

function Connect-ZG {
    param (
        [uri]$Uri,
        [string] $Version,
        [string]$Username,
        [string]$Password
    )

    if(-not [string]::IsNullOrEmpty($Version)){
        $script:Version = $Version
    }

    $response = Invoke-ZGRequest -Method "POST" -Uri ("{0}/api_jsonrpc.php" -f $Uri.OriginalString) -Body @{
        "method"  = "user.login"
        "params"  = @{
            "username" = $Username
            "password" = $Password
        }
        "id"      = $script:RequestID
        "auth"    = $null
    } 

    $script:RequestAuth = $response.result
    return $response.result
}