Have you ever tried to find out the number of users of an enterprise application in your Office 365 tenant? For apps with under 100 users it’s easy – just open Azure AD and check the user count. For more popular apps, it’s a lot more difficult, as Azure AD just shows “100+”. However, with some PowerShell magic, we can dig out the real user count!
When you have an “Enterprise Application” in your Azure AD, you can quite easily access its properties from the Azure Portal. However, if you want to find out the number of users using the app, that’s not as straightforward.
Even for less popular apps, you’ll have to be using the right Azure AD instance (there are usually multiple Azure AD instances/directories associated with your Office 365 subscription!) and have permissions to access the Azure portal. If you’re using the app to access data in SharePoint Online, see this page on how to access the right Azure AD instance.
For more popular apps (with more than a hundred users), Azure AD will just show “100+” as the user count. It appears you cannot get the actual user count by using the Azure Portal UI.
You can luckily achieve this pretty easily with PowerShell!
The following script gets the AAD Service Principal for the Enterprise Application. Since Enterprise Applications are actually registered at another directory (the one their publisher uses), your AAD instance just provisions service principals for them in your directory, adds required permissions to these principals, and then assigns users to these service principals.
By counting the number of these assignments, we can get the actual user count. These lines of some PowerShell magic should do the trick:
$app_name = "<app display name>" $sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'" $assignments = Get-AzureADServiceAppRoleAssignment -ObjectId $sp.ObjectId -All $true $assignments.Count # this row outputs the number of users of the app
That’s it. Hope it helps!
Latest posts by Antti K. Koskela (see all)
- Fastest way to verify your Client Id and Client Secret are valid with PowerShell - August 9, 2018
- How to get the user count for Azure AD Enterprise Application - August 1, 2018
- Solving “Tenant app deployment is only supported in the app catalog site. The current site is not the app catalog site.” error - July 31, 2018
- Solving “Sorry, your files couldn’t be uploaded. The upload might be too large or the server might be experiencing high network traffic.” in SharePoint - July 24, 2018