azure - 如何从 Microsoft Graph 获取 Azure 用户列表?
问题描述
基本上,我只想使用 Microsoft Graph 来获取活动目录用户及其电子邮件地址的列表。
理想情况下,我可以获得某个订阅的所有管理员用户。
我怎么做?我在网上找不到任何好的例子。
解决方案
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
推荐阅读
- react-native - 测试时未定义 ref 变量中的方法
- node.js - 如果文档已存在,则批量插入并忽略
- microservices - API Gateway 中 2 个用户之间的分隔服务
- types - 将结构转换为位数组:位流类型错误
- java - 如何多次更改 LinearLayout View 背景颜色?
- php - 带类的未定义变量
- authentication - Flutter - Rest API 身份验证到期
- python-3.x - python中多个AGV的最短路径算法
- javascript - 重写后输入JS绑定函数不运行
- ios - SIGABRT:前提条件失败:导入的节点在其值被读取之前被删除