使用 Microsoft Graph PowerShell 连接到 Microsoft Graph

什么是 Connect-MgGraph cmdlet?

Connect-MgGraph cmdlet 用于使用 Microsoft Graph PowerShell 启动与 Microsoft Graph 的连接。此命令对会话进行身份验证,并授予对 Microsoft Entra ID 资源及其他 Microsoft 365 服务的访问权限。

运行 Connect-Graph cmdlet 是执行任何其他 Graph cmdlet 之前的第一步,因为它确保会话根据提供的作用域进行身份验证和授权。

使用 Connect-MgGraph cmdlet 连接到 Microsoft Graph

前提条件

在运行 Connect-MgGraph cmdlet 之前,请确保以下事项:

  • The Microsoft Graph PowerShell SDK is installed. You can install it using the following command:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • 您拥有访问所需作用域的适当管理员或委派权限。

使用 Connect-MgGraph cmdlet

运行以下命令以连接到 Microsoft Graph:

Connect-MgGraph

示例

示例 1:使用特定作用域连接

Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All"

示例 2:连接到特定租户

Connect-MgGraph -TenantId "zkyy.com"

支持的参数

参数 描述
-Scopes 此参数可用于指定一个或多个作用域。
-TenantId 此参数可用于指定要连接的租户 ID 或域。
-ClientId 此参数可用于指定用于基于应用程序身份验证的客户端应用程序 ID。
-UseDeviceAuthentication 此参数可用于启用设备代码流进行身份验证。

使用 Graph PowerShell 脚本管理和报告 Microsoft Entra ID 的限制

  • PowerShell 缺乏 GUI,使得可视化结果或大规模管理对象变得更加困难。
  • 在自动化场景中连接和维护身份验证会话较为复杂。
  • 错误消息通常含糊不清,导致脚本执行期间调试耗时。
  • API 版本频繁更改可能导致脚本的向后兼容性中断。

ADManager Plus 是一款 IGA 解决方案,具备从单一集中控制台管理和报告混合 Active Directory 环境的能力。ADManager Plus 针对 IT 管理员设计,通过提供基于 GUI 的界面,消除了复杂 PowerShell 脚本的需求,用于日常管理任务、报告和自动化。

使用 ADManager Plus 简化 Microsoft Entra ID 管理

ADManager Plus 消除了手动 PowerShell 脚本的需求,并支持:

使用 ADManager Plus 简化 Microsoft Entra ID 管理

 
  • 什么是 Connect-MgGraph cmdlet?
  • 使用 Connect-MgGraph cmdlet 连接到 Microsoft Graph
  • 使用 Graph PowerShell 脚本管理 Microsoft Entra ID 的限制
  • 使用 ADManager Plus 简化 Entra ID 管理
Active Directory管理与报告的一站式解决方案
电子邮件下载链接 Email the ADManager Plus download link