当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

作者:精品下载站 日期:2024-12-14 03:35:16 浏览:16 分类:玩电脑

在 Microsoft Entra 和 PowerShell 中获取 MFA 状态


您不想使用 PowerShell 列出 Microsoft 365/Microsoft Entra MFA 用户状态?相反,您想要使用图形用户界面 (GUI)。不用担心,因为您可以从 Microsoft Entra 管理中心获取所有 MFA 详细信息。在本文中,您将了解如何在 Microsoft Entra 和 PowerShell 中获取 MFA 用户身份验证方法。门户网站。

在 Microsoft 租户中配置 MFA

在 Microsoft 租户中配置 MFA 有两种方法:

  1. 配置 MFA 与条件访问
  2. 配置每用户 MFA

我们推荐选项 1,因为您拥有更多控制权和更多需要配置的功能。但它需要Microsoft Entra ID P1Microsoft Entra ID P2许可证。因此,如果您买不起这些 Entra ID 版本,请选择免费的选项 2

在此过程中,请阅读文章防止组织中的 MFA 疲劳攻击并启用所示的设置以提供额外的保护。

重要提示:为每个租户启用 MFA,因为它至关重要

假设您有 Microsoft Entra ID P1 或 P2 并配置了每用户 MFA,但想要迁移到条件访问 MFA;请阅读文章从每用户 MFA 迁移到条件访问 MFA。

如何在 Microsoft Entra 中获取所有用户的 MFA 状态

按照以下步骤检查哪些用户已在 Microsoft Entra 管理中心注册 MFA:

  1. 登录 Microsoft Entra 管理中心
  2. 展开身份 > 保护
  3. 点击身份验证方法
  4. 选择用户注册详细信息

注意:您需要 Microsoft Entra ID P1 或 P2 许可证才能查看用户注册详细信息

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

  1. 检查以下列以获取 MFA 用户帐户状态:
  • 多因素身份验证能力
  • 默认多重身份验证方法
  • 注册方法

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

如果您想使用 PowerShell 获得相同的报告怎么办?让我们在下一步中看看。

使用 Microsoft Graph PowerShell 获取用户 MFA 状态

获取所有用户身份验证方法的一个绝佳方法是使用 Microsoft Graph PowerShell。

Get-AuthenticationMethods.ps1 脚本将获取所有用户的默认 MFA 方法和注册的身份验证方法,并将其导出到 CSV 文件。

对于每个用户,它都会收集以下信息:

  1. ID
  2. 用户主体名称
  3. 是管理员
  4. 默认Mfa方法
  5. 方法注册
  6. 是否有能力
  7. 已注册
  8. 无密码功能
  9. 是否有能力
  10. 是否Sspr启用
  11. 已注册
  12. IsSystemPreferredAuthenticationMethodEnabled
  13. 上次更新日期时间

步骤 1. 准备 Get-AuthenticationMethods PowerShell 脚本

(C:)驱动器上创建两个文件夹:

  • 温度
  • 脚本

下载 Get-AuthenticationMethods.ps1 PowerShell 脚本并将其放置在 C:\scripts 文件夹中。该脚本会将 CSV 文件导出到 C:\temp 文件夹。

确保文件未被阻止,以防止运行脚本时出现错误。请阅读文章运行 PowerShell 脚本时出现未数字签名错误来了解更多信息。

另一种选择是将以下代码复制并粘贴到记事本中。将其命名为 Get-AuthenticationMethods.ps1 并将其放置在 C:\scripts 文件夹中。

<#
    .SYNOPSIS
    Get-AuthenticationMethods.ps1

    .DESCRIPTION
    Export users authentication methods report from Micrososoft Graph and know which MFA method
    is set as default for each user and what MFA methods are registered for each user.

    .LINK
    www.a-d.site/get-mfa-status-entra/

    .NOTES
    Written by: ALI TAJRAN
    Website:    www.a-d.site
    LinkedIn:   linkedin.com/in/a-d

    .CHANGELOG
    V1.00, 10/12/2023 - Initial version
#>

# Export path for CSV file
$csvPath = "C:\Temp\AuthenticationReport.csv"

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All", "Group.Read.All", "UserAuthenticationMethod.Read.All", "AuditLog.Read.All"

try {
    # Fetch user registration detail report from Microsoft Graph
    $Users = Get-MgBetaReportAuthenticationMethodUserRegistrationDetail -All

    # Create custom PowerShell object and populate it with the desired properties
    $Report = foreach ($User in $Users) {
        [pscustomobject]@{
            Id                                           = $User.Id
            UserPrincipalName                            = $User.UserPrincipalName
            UserDisplayName                              = $User.UserDisplayName
            IsAdmin                                      = $User.IsAdmin
            DefaultMfaMethod                             = $User.DefaultMfaMethod
            MethodsRegistered                            = $User.MethodsRegistered -join ','
            IsMfaCapable                                 = $User.IsMfaCapable
            IsMfaRegistered                              = $User.IsMfaRegistered
            IsPasswordlessCapable                        = $User.IsPasswordlessCapable
            IsSsprCapable                                = $User.IsSsprCapable
            IsSsprEnabled                                = $User.IsSsprEnabled
            IsSsprRegistered                             = $User.IsSsprRegistered
            IsSystemPreferredAuthenticationMethodEnabled = $User.IsSystemPreferredAuthenticationMethodEnabled
            LastUpdatedDateTime                          = $User.LastUpdatedDateTime
        }
    }
    # Output custom object to GridView
    $Report | Out-GridView -Title "Authentication Methods Report"

    # Export custom object to CSV file
    $Report | Export-Csv -Path $csvPath -NoTypeInformation -Encoding utf8

    Write-Host "Script completed. Report exported successfully to $csvPath" -ForegroundColor Green
}
catch {
    # Catch errors
    Write-Host "An error occurred: $_" -ForegroundColor Red
}
  • 第 22 行:编辑 CSV 文件路径

注意:如果您要检查特定组的 MFA 状态,请替换行 272829 > 使用下面的代码。在 -GroupId 参数后添加组的唯一标识符。

try {
    # Fetch group members
    $GroupMembers = Get-MgGroupMember -GroupId "62dee815-d5c9-44ce-9085-e17f2c80734d" -All

    # Extract Ids from group members
    $GroupMemberIds = $GroupMembers.Id

    # Fetch user registration detail report from Microsoft Graph for group members
    $Users = Get-MgBetaReportAuthenticationMethodUserRegistrationDetail -All | Where-Object { $GroupMemberIds -contains $_.Id }

步骤 2. 安装 Microsoft Graph PowerShell

以管理员身份运行 Windows PowerShell 并安装 Microsoft Graph PowerShell。

Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force

重要提示:始终安装 Microsoft Graph PowerShellMicrosoft Graph Beta PowerShell 模块。这是因为某些 cmdlet 在最终版本中尚不可用,并且无法运行。在运行 cmdlet 或脚本之前将两个模块更新到最新版本,以防止出现错误和不正确的结果。

步骤 3. 连接到 Microsoft Graph PowerShell

连接到 Microsoft Graph PowerShell。

Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.Read.All", "AuditLog.Read.All"

输入您的全局管理员凭据并接受 Microsoft Graph 权限请求。

步骤 4. 运行 Get-AuthenticationMethods PowerShell 脚本

使用 PowerShell 获取所有用户身份验证方法。运行以下命令来运行脚本 Get-AuthenticationMethods.ps1。

c:\scripts\.\Get-AuthenticationMethods.ps1

Out-GridView 将显示包含所有用户及其信息的列。

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

步骤 5. 打开身份验证方法报告

Get-AuthenticationMethods.ps1 PowerShell 脚本将所有用户身份验证方法导出到 CSV 文件。在路径 C:\temp 中找到文件 AuthenticationReport.csv

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

使用您喜欢的应用程序打开 CSV 文件。在我们的示例中,它是 Microsoft Excel。

[玩转系统] 在 Microsoft Entra 和 PowerShell 中获取 MFA 状态

就是这样!

多重身份验证常见问题解答

当用户帐户的状态可用不可用出现在列表中时,将会出现问题。以下是您可能有的主要问题及其答案。

有能力和没有能力有什么区别?

  • 有能力:为用户帐户设置 MFA
  • 无法:未为用户帐户设置 MFA

多重身份验证何时显示为“可用”?

如果用户完成 MFA 向导配置,它将显示为可用。因此,只要用户没有完成 MFA 设置,就会显示为无法

如果您为用户启用或强制执行每用户 MFA,并且用户未配置 MFA,则它仍显示为无法。如果您配置 MFA 条件访问并将用户添加到策略中,这同样适用。如果用户未配置 MFA,则显示为无法

每用户 MFA 和条件访问 MFA 是否出现在列表中?

是的,每用户 MFA 和条件访问 MFA 用户及其身份验证方法将显示在列表中。

重要提示:使用条件访问启用 MFA 时,请为所有用户禁用每用户 MFA。

注意:对于显示为无法的用户帐户,请联系用户并提醒他们完成 MFA 设置向导。

了解更多:通过条件访问确保 MFA 和 SSPR 注册安全 »

结论

您了解了如何在 Microsoft Entra 和 PowerShell 中获得 MFA 状态。 Microsoft Entra 管理中心中的身份验证方法部分非常棒。这有助于希望避免使用 PowerShell 获取 MFA 状态信息的管理员。

每个用户都必须配置多重身份验证,通过查看身份验证方法中的用户注册详细信息,您可以快速识别使用了哪些 MFA 方法以及哪些人还需要配置 MFA。

您喜欢这篇文章吗?您可能还喜欢条件访问 MFA 中断 Azure AD Connect 同步。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯