Azure AD - Graph API request to pull all departments

天涯浪子 提交于 2021-01-28 04:21:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!