I'm trying to get list of all users from Azure Active Directory using the below code, but still I'm getting only 100 records at one time.
I'm using DOTNET Core version 7
var scopes = new string[] { "https://graph.microsoft.com/.default" };
var confidentialClient = ConfidentialClientApplicationBuilder
.Create(ClientId)
.WithAuthority($"https://login.microsoftonline.com/" + TenantId + "/v2.0")
.WithClientSecret(ClientSecret)
.Build();
GraphServiceClient graphServiceClient =
new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
// Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
var authResult = await confidentialClient.AcquireTokenForClient(scopes).ExecuteAsync();
// Add the access token in the Authorization header of the API
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
})
);
var users = await graphServiceClient.Users.Request().GetAsync();
I want to get all the users from Azure AD.
I tried this line of code:
var users = await graphServiceClient.Users.Request().GetAsync();
but I'm getting only 100 records, there are about 1500 records in Azure AD, I want to get all those records.
I do agree with @Dai, you need to supply range, Or you can use Top() Operator in your code like:
Alternatively you can use below code which I followed from SO-thread and GithubDoc:
Output: