New-MgServicePrincipalAppRoleAssignment : Resource '1***1' does not exist or one of its queried reference-property objects are not present

john john Pter 1,065 Reputation points
2025-04-23T22:30:14.5833333+00:00

I have an azure function and i enable its managed identity , and i got a principle id "1***1":-

User's image

now i tried to run this commands:-

Connect-MgGraph -Scope "Application.Read.All", "AppRoleAssignment.ReadWrite.All"

$managedIdentityObjectId = "1***1"

$scopeName = "Sites.Selected"

$resourceAppPrincipalObj = Get-MgServicePrincipal -Filter "displayName eq 'Office 365 SharePoint Online'"

$targetAppPrincipalAppRole = $resourceAppPrincipalObj.AppRoles | ? Value -eq $scopeName

$appRoleAssignment = @{

"principalId" = $managedIdentityObjectId

"resourceId" = $resourceAppPrincipalObj.Id

"appRoleId" = $targetAppPrincipalAppRole.Id

}

New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $managedIdentityObjectId -BodyParameter $appRoleAssignment | Format-List

but got this error:-

New-MgServicePrincipalAppRoleAssignment : Resource '1***1' does not exist or one of its queried reference-property objects are not present. Status: 404 (NotFound) ErrorCode: Request_ResourceNotFound Date: 2025-04-23T22:20:58 Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 040d2f19-76a0-4972-b509-100ec172d5b0 client-request-id : f853a3b5-ebd5-46b1-85dd-9dd9ad5afeb6 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Italy North","Slice":"E","Ring":"3","ScaleUnit":"002","RoleInstance":"MI3PEPF000001C0"}} x-ms-resource-unit : 1 Cache-Control : no-cache Date : Wed, 23 Apr 2025 22:20:58 GMT At line:1 char:1 + New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $managedI ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ({ ServicePrinci...oleAssignment }:<>f__AnonymousType23) [New-MgServi cePr...signment_Create], Exception + FullyQualifiedErrorId : Request_ResourceNotFound,Microsoft.Graph.PowerShell.Cmdlets.NewMgServicePrincipalAppRole Assignment_Create

so what could be the reason for this error?

Microsoft Security | Microsoft Entra | Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.