问题
I'm testing some things out using the Windows Graph API, connecting to an Azure AD. So far, I am able to pull the User information for a given user object id. This is great, as it shows the Department and that is what I'm wanting to find. However, it there a call I can make that will list out ALL Departments currently in the AD? I need to pull all of them so I can see what is defined, and add logic to my program to allow certain departments access to certain areas.
Thank you!
回答1:
You once only get the departments in the identical tenant id. Getting department code like this:
try
{
List<IUser> users = activeDirectoryClient.Users.ExecuteAsync().Result.CurrentPage.ToList();
List<string> departmentlist = new List<string>();
var i = 0;
foreach (IUser user in users)
{
if (user.Department != null)
{
string depName = user.Department.ToString();
departmentlist.Add(depName);
Console.WriteLine("UserDepartmentName:{0}", departmentlist[i]);
i++;
}
}
}
catch (Exception e)
{
Console.WriteLine("\nError getting department {0} {1}",
e.Message, e.InnerException != null ? e.InnerException.Message : "");
}
来源:https://stackoverflow.com/questions/35992494/azure-ad-graph-api-request-to-pull-all-departments