Microsoft Entra ID 保护和 Microsoft Graph PowerShell

Microsoft Graph 是 Microsoft 的统一 API 终结点,也是 Microsoft Entra ID 保护 API 的所在位置。 本文介绍如何使用 Microsoft Graph PowerShell SDK 通过 PowerShell 管理风险用户。 如果组织要直接查询 Microsoft Graph API,则可以参阅教程:使用 Microsoft Graph API 识别和修正风险一文来开始这段旅程。

要成功完成本教程,请确保具备所需的先决条件:

  • 已安装 Microsoft Graph PowerShell SDK。 有关详细信息,请参阅安装 Microsoft Graph PowerShell SDK 一文。

  • 使用安全管理员角色的 Microsoft Graph PowerShell。 需要 IdentityRiskEvent.Read.All、IdentityRiskyUser.ReadWrite.All 或 IdentityRiskyUser.ReadWrite.All 委派权限。 要设置 IdentityRiskEvent.Read.All 和 IdentityRiskyUser.ReadWrite.All 权限,请运行以下命令:

    Connect-MgGraph -Scopes "IdentityRiskEvent.Read.All","IdentityRiskyUser.ReadWrite.All"
    

如果使用仅限应用的身份验证,请参阅将仅限应用的身份验证与 Microsoft Graph PowerShell SDK 配合使用一文。 要使用所需的应用程序权限注册应用程序,请准备证书并运行以下命令:

Connect-MgGraph -ClientID YOUR_APP_ID -TenantId YOUR_TENANT_ID -CertificateName YOUR_CERT_SUBJECT ## Or -CertificateThumbprint instead of -CertificateName

使用 PowerShell 列出风险检测

可在 ID 保护中通过风险检测的属性检索风险检测。

# List all anonymizedIPAddress risk detections
Get-MgRiskDetection -Filter "RiskType eq 'anonymizedIPAddress'" | Format-Table UserDisplayName, RiskType, RiskLevel, DetectedDateTime

# List all high risk detections for the user 'User01'
Get-MgRiskDetection -Filter "UserDisplayName eq 'User01' and Risklevel eq 'high'" | Format-Table UserDisplayName, RiskType, RiskLevel, DetectedDateTime

使用 PowerShell 列出风险用户

可在 ID 保护中检索有风险的用户及其风险历史记录。

# List all high risk users
Get-MgRiskyUser -Filter "RiskLevel eq 'high'" | Format-Table UserDisplayName, RiskDetail, RiskLevel, RiskLastUpdatedDateTime

#  List history of a specific user with detailed risk detection
Get-MgRiskyUserHistory -RiskyUserId 375844b0-2026-4265-b9f1-ee1708491e05| Format-Table RiskDetail, RiskLastUpdatedDateTime, @{N="RiskDetection";E={($_). Activity.RiskEventTypes}}, RiskState, UserDisplayName

使用 PowerShell 确认被入侵的用户

可以确认被入侵的用户,并在 ID 保护中将其标记为高风险用户。

# Confirm Compromised on two users
Confirm-MgRiskyUserCompromised -UserIds "577e09c1-5f26-4870-81ab-6d18194cbb51","bf8ba085-af24-418a-b5b2-3fc71f969bf3"

使用 PowerShell 消除风险用户

可在 ID 保护中批量消除有风险的用户。

# Get a list of high risky users which are more than 90 days old
$riskyUsers= Get-MgRiskyUser -Filter "RiskLevel eq 'high'" | where RiskLastUpdatedDateTime -LT (Get-Date).AddDays(-90)
# bulk dismiss the risky users
Invoke-MgDismissRiskyUser -UserIds $riskyUsers.Id

后续步骤