首页 > 解决方案 > 如何从 Microsoft Graph 获取 Azure 用户列表?

问题描述

基本上,我只想使用 Microsoft Graph 来获取活动目录用户及其电子邮件地址的列表。

理想情况下,我可以获得某个订阅的所有管理员用户。

我怎么做?我在网上找不到任何好的例子。

标签: azureazure-active-directorymicrosoft-graph-api

解决方案


Assuming you have the correct access to a tenant, and an authenticated token granting you access to the Microsoft Graph, you can use the following REST API calls to get the data you are looking for:

List Users - Documentation

GET https://graph.microsoft.com/v1.0/users

List Admins (via directory roles) - Documentation

This is a multi-step process. First you must find the directory role for the Company Administrator, which will always have the roleTemplateId of 62e90394-69f5-4237-9190-012177145e10. This should not be confused by the actual directory role id, which will be different per directory.

GET https://graph.microsoft.com/v1.0/directoryRoles

Then you want to list the users who are a part of that directory role:

GET https://graph.microsoft.com/v1.0/directoryRoles/<id>/members

If you really need to get started from scratch, I recommend you look at this PowerShell sample I made which simplifies authentication, and allows you to make queries to resource endpoints like the Microsoft Graph.

https://github.com/shawntabrizi/Microsoft-Authentication-with-PowerShell-and-MSAL


推荐阅读