The New-MgServicePrincipal cmdlet is a powerful tool in the Microsoft Graph PowerShell module enabling administrators to create new service principals within the Microsoft 365 directory. This article delves into the syntax, usage example, tips, use cases, common errors and solutions relating to the cmdlet.
Install-Module Microsoft.Graph -Scope CurrentUser
New-MgServicePrincipal -BodyParameter <Object>
Here’s a straightforward example of creating a new service principal using the cmdlet:
$ServicePrincipalID = @{
"AppId" = "fc876dd1-6bcb-4304-b9b6-18ddf1526b62"
}
New-MgServicePrincipal -BodyParameter $ServicePrincipalID | Format-List id DisplayName AppId SignInAudience
This script creates a service principal with the specified AppId and then formats the output to list key properties.
Expected Output:
Id : ac483a5f-f291-4499-8a62-058547724579
DisplayName : Example App
AppId : ffdf268a-2fe2-49e1-8cd7-66ecb61641ec
SignInAudience : AzureADandPersonalMicrosoftAccount
Insufficient Permissions:
Error: Authorization_RequestDenied
Solution: Ensure the user has the necessary Azure AD permissions to create service principals.
Invalid AppId:
Error: Request_BadRequest
Solution: Verify that the AppId provided in the -BodyParameter is correct and corresponds to a registered application.
Malformed JSON:
Error: Invalid request
Solution: Check the JSON structure in the -BodyParameter for syntax errors and ensure all required fields are included.
The New-MgServicePrincipal cmdlet is essential for managing application identities within an Azure AD tenant. By understanding its syntax, usage, and handling common errors, M365 administrators can leverage this cmdlet to enhance security, automate tasks, and integrate applications efficiently.
© m365corner.com. All Rights Reserved. Design by HTML Codex