public/serviceEndpoint/Add-PSTSServiceEndPointGit.ps1

#$password =(get-content $credFile) | ConvertTo-SecureString
#$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($password)
#$result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
#[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
#$result
#
function Add-PSTSServiceEndPointGit
{
    param(
         [string] $project,
         [string] $name,
         [string] $username,
         [string] $password,
         [string] $url
    )

    process {



        [EndpointAuthorization] $authorization = [EndpointAuthorization]::new()
        $authorization.scheme = "UsernamePassword"
        $authorization.parameters = New-Object System.Collections.Specialized.OrderedDictionary
        $authorization.parameters.Add("password","$password")
        $authorization.parameters.Add("username","$username")





        [ServiceEndpoint] $serviceEndpoint = [ServiceEndpoint]::new()
        $serviceEndpoint.name="$name"
        $serviceEndpoint.type = "git"
        $serviceEndpoint.url = "$url"
        $serviceEndpoint.authorization = $authorization
        $serviceEndpoint.data = New-Object System.Collections.Specialized.OrderedDictionary
        $serviceEndpoint.data.Add( "accessExternalGitServer","true")





        $content = `
        _PSTSAPI `
            -project $project `
            -resource "serviceendpoint/endpoints" `
            -method "POST" `
            -body $($serviceEndpoint | ConvertTo-Json) `
            -contentType "application/json" `
            -apiVersion "api-version=5.2-preview.2"
                        #-apiVersion "api-version=5.1-preview"
        return [Object]$content
    }
}