你当前正在访问 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"
创建新的应用注册
- 在 Azure 门户中,浏览到“Azure Active Directory”>“应用注册”。
- 选择“新注册”。
- 在“创建”页中,执行以下步骤:
- 在“名称”文本框中,键入应用程序的名称例如:Azure AD 风险检测 API)。
- 在“受支持的帐户类型”下,选择将使用 API 的帐户类型。
- 选择“注册”。
- 记下“应用程序(客户端) ID”和“目录(租户) ID”,因为你稍后将需要用到这些项。
配置 API 权限
在此示例中,我们配置应用程序权限,允许在无人参与的情况下使用此示例。 若要向将登录的用户授予权限,请改为选择“委托的权限”。 若要详细了解不同权限类型,请参阅 Microsoft 标识平台中的权限和同意一文。
- 从创建的“应用程序”中,选择“API 权限”。
- 在“配置权限”页中,在顶部工具栏中单击“添加权限”。
- 在“添加 API 访问权限”页中,单击“选择 API”。
- 在“选择 API”页中,选择“Microsoft Graph”,然后单击“选择”。
- 在“请求 API 权限”页中:
- 选择“应用程序权限”。
- 选中“
IdentityRiskEvent.Read.All”和“IdentityRiskyUser.Read.All”旁边的复选框。 - 选择“添加权限”。
- 选择“为域授予管理员同意”
配置有效凭据
- 从你创建的“应用程序”中,选择“证书 & 机密”。
- 在“证书”下,选择“上传证书”。
- 在随即打开的窗口中,选择之前导出的证书。
- 选择“添加”。
- 记下证书的“指纹”,因为在下一步中你将需要用到此信息。
使用 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