Private/New-URLEncode.ps1

function New-URLEncode {
    param(
        [parameter(Mandatory)]
        [string] $URL,
        [parameter()]
        [string] $context = 'sdpconnection'
    )

    $server = Get-Variable -Scope Global -Name $context -ValueOnly -ErrorAction SilentlyContinue

    if (-not $server) {
        throw "New-URLEncode: No variable found for context '$context'. Please ensure you have logged in with the correct context or specify the correct context variable name."   
    } else {
        Write-Verbose "New-URLEncode: Found variable for context '$context'. Using its K2Endpoint value for URL encoding."  
    }

    $baseurl = 'https://' + $server.K2Endpoint
    $url = $url.Replace($baseurl,$null)
    $url = $url.Replace(':','%3A').replace('.','%2E')
    $url = $baseurl + $url
    # write-verbose "-- Invoke-SDPRestCall --> New-URLEncode -> Using URLEncode $url"
    return $url
}