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
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.
does not exist or one of its queried reference-property objects are not presenterror.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.
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.