public/serviceEndpoint/Add-PSTSServiceEndPointAzurerm.ps1

function Add-PSTSServiceEndPointAzurerm
{
    param(
         [string] $project,
         [string] $name,
         [string] $servicePrincipaleId,
         [string] $servicePrincipaleKey,
         [string] $subscriptionId,
         [string] $subscriptionName,
         [string] $tenantId
    )

    process {

        [ServiceEndpoint] $serviceEndpoint = [ServiceEndpoint]::new()
        $serviceEndpoint.name="$name"
        $serviceEndpoint.type = "azurerm"
        $serviceEndpoint.url = "https://management.azure.com/"
        [EndpointAuthorization] $authorization = [EndpointAuthorization]::new()
        $authorization.scheme = "ServicePrincipal"
        $authorization.parameters = New-Object System.Collections.Specialized.OrderedDictionary
        $authorization.parameters.Add("tenantid","$tenantid")
        $authorization.parameters.Add("serviceprincipalid","$servicePrincipaleId")
        $authorization.parameters.Add("authenticationType", "spnKey")
        $authorization.parameters.Add("serviceprincipalkey", "$servicePrincipaleKey")
        $serviceEndpoint.authorization = $authorization
        $serviceEndpoint.data = New-Object System.Collections.Specialized.OrderedDictionary
        $serviceEndpoint.data.Add( "subscriptionId","$subscriptionId")
        $serviceEndpoint.data.Add("subscriptionName", "$subscriptionName")
        $serviceEndpoint.data.Add("environment", "AzureCloud")
        $serviceEndpoint.data.Add( "scopeLevel", "Subscription")
        $serviceEndpoint.data.Add( "creationMode", "Manual")
        $serviceEndpoint.data.Add("azureSpnRoleAssignmentId", "")
        $serviceEndpoint.data.Add("azureSpnPermissions", "")
        $serviceEndpoint.data.Add("spnObjectId", "")
        $serviceEndpoint.data.Add( "appObjectId", "")

        $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
    }
}