다음을 통해 공유


Azure AD Graph API Create List of Users

Getting the list of users from AD is bit tricky. Firstly the call is Asynchronous and it is delayed. So no such straight forward foreach loop can help, Define the data model

After that we can write something like,

private async Task GetUsers()

{

List<UserGridData> userData = new List<UserGridData>();

var adClient = GetAADClient();

 

var userListTask = adClient.Users.ExecuteAsync();

var userList = await userListTask;

do

{

foreach (var userObject in userList.CurrentPage.ToList())

{

var userValue = (User) userObject;

userData.Add(

new UserGridData()

{

UserId = userValue.ObjectId,

UserPrincipleName = userValue.UserPrincipalName

}

);

}

} while (userList.MorePagesAvailable);

 

dataGridView1.DataSource = userData;

}

 

I have displayed the data in a Grid you may handle it as per your need.

Namoskar!!!