jmknight2
jmknight2

Reputation: 109

How to get list of users along with manager information in a single call via Get-AzureAdUser?

I am attempting to pull down a list of users from our Azure AD tenant. Currently, I'm using Get-AzureAdUser which returns almost everything I need. However, I also need to know each user's manager, which doesn't appear in the response from Get-AzureAdUser. Currently, I've not been able to find this without making a separate call to another cmdlet, Get-AzureAdUserManager. This is slowing down the entire process considerably. Obviously, I'd like to limit this to one call and receive all necessary data in one go. Is this in anyway possible?

Thanks in advance for your help!

Upvotes: 1

Views: 4676

Answers (1)

Rohit Saigal
Rohit Saigal

Reputation: 9674

AFAIK you won't be able to get user information as well as their manager information in a single call using Get-AzureADUser

ALTERNATIVES

Azure AD Graph API

This is the API that PowerShell also uses behind the scenes. Here you can make use of $expand operator get a resource and some of it's navigation properties in a single call.

https://graph.windows.net/myorganization/users?$expand=manager&api-version=1.6
or
https://graph.windows.net/{tenant-id}/users?$expand=manager&api-version=1.6

You can quickly try this query out in Azure AD Graph Explorer.

Please know that it can get heavy with a lot of data being returned, especially since I didn't see $expand and $select working together, in order to return only those fields that you're interested in. This would be a design consideration for your case.

NOTE: In most cases it's recommended to use newer Microsoft Graph API over Azure AD Graph API, read more here Microsoft Graph or Azure AD Graph. Your particular case is such that query required is not supported with v1.0 endpoint for Microsoft Graph API, so I have mentioned Azure AD Graph API. See that in next section.

Microsoft Graph API

Microsoft Graph API can help you query user information. Individual API's to query user and manager are List Users and List Manager

More interestingly with Microsoft Graph API you can use $expand operator to try and get a resource and some of it's navigation properties in a single call.

https://graph.microsoft.com/beta/users?$expand=manager

You can quickly try this out in Microsoft Graph Explorer.

NOTE: Please notice that I'm using the beta endpoint here. It is not recommended to use the beta endpoint API's with production code.

Same query is not supported with the stable v1.0 endpoint and hence I recommended Azure AD Graph API above.

/* Does NOT work */
https://graph.microsoft.com/v1.0/users?$expand=manager   

Upvotes: 1

Related Questions