public/serviceEndpoint/Add-PSTSServiceEndPointExternaltfs.ps1

#{"count":1,"value":[{"data":{},"id":"e7adb3d9-d33e-425d-bb65-d8282c795d01","name":"test feeds","type":"externaltfs","url":"https://tgits-code.visualstudio.com","createdBy":{"displayName":"Mathieu GRAVIL","url":"https://spsprodweu3.vssps.visualstudio.com/Ab9971e20-bdd9-48e2-8888-2a176631d0f2/_apis/Identities/766ad09b-7243-6a3d-b31f-ad0ff90beda1","_links":{"avatar":{"href":"https://dev.azure.com/dataops-total/_apis/GraphProfile/MemberAvatars/aad.NzY2YWQwOWItNzI0My03YTNkLWIzMWYtYWQwZmY5MGJlZGEx"}},"id":"766ad09b-7243-6a3d-b31f-ad0ff90beda1","uniqueName":"Mathieu.Gravil@Total.com","imageUrl":"https://dev.azure.com/dataops-total/_apis/GraphProfile/MemberAvatars/aad.NzY2YWQwOWItNzI0My03YTNkLWIzMWYtYWQwZmY5MGJlZGEx","descriptor":"aad.NzY2YWQwOWItNzI0My03YTNkLWIzMWYtYWQwZmY5MGJlZGEx"},"description":"","authorization":{"scheme":"Token"},"isShared":false,"isReady":true,"owner":"Library","serviceEndpointProjectReferences":[{"projectReference":{"id":"cde101b9-5ec0-4850-a1b8-ecbec84bd5a8","name":"Test_project"},"name":"test feeds","description":""}]}]}

function Add-PSTSServiceEndPointExternaltfs
{
    param(
         [string] $project,
         [string] $serviceConnectionName,
         [string] $pat,
         [string] $url,
         [bool] $isShared
    )

    process {

        [ServiceEndpoint] $serviceEndpoint = [ServiceEndpoint]::new()
        $serviceEndpoint.name="$serviceConnectionName"
        $serviceEndpoint.type = "externaltfs"
        $serviceEndpoint.isShared = $isShared
        [EndpointAuthorization] $authorization = [EndpointAuthorization]::new()
        $authorization.scheme = "Token"
        $authorization.parameters = New-Object System.Collections.Specialized.OrderedDictionary
        $authorization.parameters.Add("apitoken","$pat")
        $serviceEndpoint.isShared = $isShared
        
        $serviceEndpoint.authorization = $authorization
        
        $serviceEndpoint.url = $url

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

        return [object]$content
    }
}