Managing multiple Azure App Registrations and Enterprise apps can be overwhelming, especially when you need to add owners manually. To save time, I’ve created a PowerShell script that lets you bulk add owners to Azure App Registrations and Enterprise apps. This is useful when you have a list of users to assign as owners across several apps.
VERY IMPORTANT SECURITY NOTICE: adding owners to app registrations and enterprise apps is a risky operation. Owners have complete control over the app, including modifying it, changing secrets, adding other owners, and deleting it. Ensure you only add trusted users as owners. Use the scripts from this post at your own risk.
Prerequisites
Before running the script, ensure you have the necessary privileges to manage app registrations and enterprise apps. You must have one of the following roles:
- Cloud Application Administrator
- Application Administrator
You can also modify app registrations that you are already an owner of.
Collecting the Required Data
To use the script, you’ll need the following information:
- User Object IDs: Get the object IDs of the users you want to add as owners.
- App Registration Object IDs: Collect the object IDs of the app registrations. This is different from the client ID.
Pro Tip: You can get the app registrations with one of the following Azure CLI commands:
1 2 3 4
# get all app registrations az ad app list --query "[].{name:displayName, objectId:id}" # search by display name (contains is not supported) az ad app list --query "[].{name:displayName, objectId:id}" --filter "startswith(displayName, 'myapp')"
- Enterprise App Object IDs: Gather the object IDs of the enterprise apps you want to add owners to.
Pro Tip: Use one of the following commands to retrieve the enterprise apps:
1 2 3 4
# get all enterprise apps az rest --method get --url "https://graph.microsoft.com/v1.0/servicePrincipals?\`$select=id,displayName" # search display name contains myapp az rest --method get --url "https://graph.microsoft.com/v1.0/servicePrincipals?\`$search='displayName:myapp'\`$select=id,displayName"
Adding Owners to App Registrations
Note: If a user is already an owner, no error will be shown.
Here’s the PowerShell script to bulk add owners to app registrations:
|
|
Adding Owners to Enterprise Apps
Note: If a user is already an owner, the script will return: “One or more added object references already exist for the following modified properties: ‘owners’.”
Unlike App Registrations, there isn’t a direct Azure CLI command to add owners to Enterprise Apps. Instead, you’ll need to use a REST request to the Microsoft Graph API. For convenience, you can still use the Azure CLI’s az rest
command, which automatically handles authorization by including the necessary token. Here’s a script to add multiple users to multiple Enterprise Apps:
|
|
Conclusion
Adding owners to multiple Azure App Registrations and Enterprise Apps can be time-consuming. By using the PowerShell scripts above, you can save time and effort. Remember to replace the object IDs with the actual values before running the scripts.
Cheers,
Lucas