functions/azure/New-ServicePrincipal.ps1

function New-ServicePrincipal {
    param (
        [Parameter(Mandatory = $true)]
        [string]$ApplicationId
    )

    $headers = @{
        Authorization = Get-RequestHeaderAuthorization -RequestUri 'https://graph.microsoft.com'
        "Content-Type" = "application/json"
    }

    $spPayload = @{ appId = $ApplicationId } | ConvertTo-Json
    $spResponse = Invoke-RestMethod -Method POST `
        -Uri "https://graph.microsoft.com/v1.0/servicePrincipals" `
        -Headers $headers -Body $spPayload

    return $spResponse
}