• As per your query, the ‘’ is occurring multiple times in the related script because ‘object-id’ and the ‘principal-id’ of the app in one tenant is different as object-id refers to the unique id of the app registered in that tenant and the principal-id refers to the entity that requires access to that application in that tenant or across other tenants. The principal-id refers to the service principal object that defines the access policy and the permissions for that application in the Azure AD tenant.
• Whereas ‘role-id’ is the azure built-in role based on azure role-based access control functionality that is to be assigned to that application or any custom azure role that is created for assigning the scoped access controls and permissions within that concerned role, i.e., may that be ‘contributor’ or ‘user access administrator’.
‘New-AzureADServiceAppRoleAssignment `
-ObjectId <object-id-of-sp-in-one-tenant> `
-Id <role-id> `
-PrincipalId <object-id-of-sp-in-one-tenant> `
-ResourceId <app-id-in-other-tenant>’
• Thus, you can refer to the script in the other thread and replace the object-id and the principal-id with the ones in your environment appropriately. Also, you can try granting database access to a managed identity user in Azure AD for this purpose. You can do this by connecting to a SQL database with a system-assigned managed identity.
• Once, managed identity on app is enabled, grant permissions to that managed identity in SQL Database with the required SQL security role on the SQL prompt. Once done, modify the SQL connection string and publish the changes done. Also, ensure to enter the appropriate app-id and user-id in the powershell commands to assign the managed identity to access SQL database with the enterprise app registration. Please find the below documentation link for more details on creating a managed identity for the SQL DB for an application across the tenants: -
https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi?tabs=windowsclient%2Cdotnet
https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app?pivots=platform-windows