你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure Active Directory 标识保护和 Microsoft Graph PowerShell SDK

Microsoft Graph 是 Microsoft 的统一 API 终结点,并且是 Azure Active Directory 标识保护 API 的主页。 本文介绍了如何使用 Microsoft Graph PowerShell SDK 通过 PowerShell 获取风险用户详细信息。 如果组织要直接查询 Microsoft Graph API,则可以参阅教程:使用 Microsoft Graph API 识别和修正风险一文来开始这段旅程。

连接到 Microsoft Graph

通过 Microsoft Graph 访问“标识保护”数据需要执行四个步骤:

创建证书

在生产环境中,你将使用生产证书颁发机构颁发的证书,但在此示例中,我们将使用自签名证书。 运行下面的 PowerShell 命令,以创建并导出证书。

$cert = New-SelfSignedCertificate -Subject "CN=MSGraph_ReportingAPI" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature -KeyLength 2048 -KeyAlgorithm RSA -HashAlgorithm SHA256
Export-Certificate -Cert $cert -FilePath "C:\Reporting\MSGraph_ReportingAPI.cer"

创建新的应用注册

  1. 在 Azure 门户中,浏览到“Azure Active Directory”>“应用注册”。
  2. 选择“新注册”。
  3. 在“创建”页中,执行以下步骤:
    1. 在“名称”文本框中,键入应用程序的名称例如:Azure AD 风险检测 API)。
    2. 在“受支持的帐户类型”下,选择将使用 API 的帐户类型。
    3. 选择“注册”。
  4. 记下“应用程序(客户端) ID”和“目录(租户) ID”,因为你稍后将需要用到这些项。

配置 API 权限

在此示例中,我们配置应用程序权限,允许在无人参与的情况下使用此示例。 若要向将登录的用户授予权限,请改为选择“委托的权限”。 若要详细了解不同权限类型,请参阅 Microsoft 标识平台中的权限和同意一文。

  1. 从创建的“应用程序”中,选择“API 权限”。
  2. 在“配置权限”页中,在顶部工具栏中单击“添加权限”。
  3. 在“添加 API 访问权限”页中,单击“选择 API”
  4. 在“选择 API”页中,选择“Microsoft Graph”,然后单击“选择”
  5. 在“请求 API 权限”页中:
    1. 选择“应用程序权限”。
    2. 选中“IdentityRiskEvent.Read.All”和“IdentityRiskyUser.Read.All”旁边的复选框。
    3. 选择“添加权限”。
  6. 选择“为域授予管理员同意”

配置有效凭据

  1. 从你创建的“应用程序”中,选择“证书 & 机密”。
  2. 在“证书”下,选择“上传证书”。
    1. 在随即打开的窗口中,选择之前导出的证书。
    2. 选择“添加”。
  3. 记下证书的“指纹”,因为在下一步中你将需要用到此信息。

使用 PowerShell 列出风险用户

若要启用查询 Microsoft Graph 这项功能,需要使用 Install-Module Microsoft.Graph 命令在 PowerShell 窗口中安装 Microsoft.Graph 模块。

修改下面的变量以包含前面步骤中生成的信息,然后使用 PowerShell 整体运行这些变量来获取风险用户详细信息。

$ClientID       = "<your client ID here>"        # Application (client) ID gathered when creating the app registration
$tenantdomain   = "<your tenant domain here>"    # Directory (tenant) ID gathered when creating the app registration
$Thumbprint     = "<your client secret here>"    # Certificate thumbprint gathered when configuring your credential

Select-MgProfile -Name "beta"
  
Connect-MgGraph -ClientId $ClientID -TenantId $tenantdomain -CertificateThumbprint $Thumbprint

Get-MgRiskyUser -All

后续步骤