I created an Azure function and enabled the managed identity option. It creates a new Enterprise application with a unique guid. I would like to add this managed identity as an owner of a specific AAD group. In the browser it works when I enter the managed identity guid, but when I try it by PowerShell code I get the error below:

Add-PnPMicrosoft365GroupMember -Identity $aadGroupId -Users $guidOfMyManagedIdentityServicePrincipal

Not Found (404): Resource 'guidOfMyManagedIdentityServicePrincipal' does not exist or one of its queried reference-property objects are not present
1

There are 1 best solutions below

2
Ikhtesam Afrin On

Add-PnPMicrosoft365GroupMember and Add-PnPMicrosoft365GroupOwner adds users to the Microsoft 365 group type but here you are adding an application. I believe it only allows to add users in it.

  • If you will try to add the Enterprise application which is created by enabling managed identity manually from Admin center then your application will not be visible in the search result.

enter image description here

enter image description here

  • Due to this you are getting does not exist or one of its queried reference-property objects are not present error.

Portal-

If you will add the enterprise application as owner in portal directly, it will get added but it won't be visible in Admin center.

enter image description here

To add the owner in the portal you can use the PowerShell script Add-AzureADGroupOwner -ObjectId "e83adea" -RefObjectId "<ManagedIdentityGuid>" in azure function.

AFAIK, Add-PnPMicrosoft365GroupOwner -Identity "e83ad3a" -Users "UsersObjectId" will work for Users. It works while adding an users in function app.

$siteUrl = "https://******.sharepoint.com"
Connect-PnPOnline $siteUrl -ManagedIdentity

Add-PnPMicrosoft365GroupOwner -Identity "e8*****a3a" -Users "<user principal>"

enter image description here

enter image description here