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

[玩转系统] 导出所有 Microsoft 365 用户 MFA 状态报告

作者:精品下载站 日期:2024-12-14 09:14:31 浏览:15 分类:玩电脑

导出所有 Microsoft 365 用户 MFA 状态报告


您可以在 Microsoft Entra 管理中心 (Azure AD) 中检查每个用户的 Microsoft 身份验证方法状态。缺点是它不会向您显示详细信息。要在单个 CSV 文件中获取所有用户 MFA 状态的列表,您需要运行 PowerShell 脚本。在本文中,您将了解如何使用 PowerShell 将所有 Microsoft 365 用户 MFA 状态报告导出到 CSV 文件。

Microsoft 365 Azure 用户 MFA 状态

每个用户都有一个登录密码,但这并不意味着他们启用了多重身份验证。您可以检查组织中的哪些用户启用了 MFA 以及他们使用哪些身份验证方法。若要概览所有 Microsoft 365 Azure 用户 MFA 状态,最好使用 PowerShell 将其导出到 CSV 文件报告。

在 Microsoft Entra 管理中心中,您可以查看和下载所有用户的 MFA 状态列表。它显示了每个用户注册的身份验证方法以及默认的 MFA 方法。

不同之处在于,您无法轻松找到哪些用户配置了特定的身份验证方法。要获得所有用户 MFA 状态的结构化概览,您需要使用 PowerShell 脚本并将其导出到 CSV 文件。

Microsoft MFA 身份验证方法

PowerShell 脚本将显示为所有 Azure AD 用户启用了哪些注册身份验证方法的概述。

Email

使用电子邮件地址作为自助密码重置 (SSPR) 流程的一部分。

Fido2

使用 FIDO2 安全密钥登录 Azure AD。

Microsoft Authenticator

使用 Microsoft Authenticator 登录 Azure AD 或执行多重身份验证。

Phone

用户可以使用电话通过短信或语音呼叫进行身份验证(在策略允许的情况下)。

SoftwareOath

使用 Microsoft Authenticator 登录 Azure AD 或执行多重身份验证。

TemporartAccessPass

临时访问通行证是一个有时间限制的密码,可作为强大的凭据并允许使用无密码凭据。

WindowsHelloForBusiness

Windows Hello 企业版是 Windows 设备上的无密码登录方法。

连接到 Microsoft Graph PowerShell

在运行 Export-MFAstatus.ps1 PowerShell 脚本之前,您需要安装 Microsoft Graph PowerShell 模块。

运行以下命令来安装 Microsoft Graph 模块。

Install-Module Microsoft.Graph -Force

注意:我们还建议您安装 Microsoft Graph Beta 模块,否则脚本将无法运行。

运行以下命令安装 Microsoft Graph Beta 模块。

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

下载 MFA 状态 PowerShell 脚本

您可以将所有用户的 MFA 状态导出到 CSV 文件。如果您还没有名为 scripts 的文件夹,则需要创建一个文件夹。

下载 Export-MFAstatus.ps1 PowerShell 脚本并将其保存在 C:\scripts 文件夹中。

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

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

# Create variable for the date stamp
$LogDate = Get-Date -f yyyyMMddhhmm

# Define CSV file export location variable
$Csvfile = "C:\temp\MFAUsers_$LogDate.csv"

# Get all Azure users using the Microsoft Graph Beta API
$users = Get-MgBetaUser -All

# Initialize the results array
$results = @()

# Initialize progress counter
$counter = 0
$totalUsers = $users.Count

# Loop through each user account
foreach ($user in $users) {
    $counter++
    
    # Calculate percentage completion
    $percentComplete = [math]::Round(($counter / $totalUsers) * 100)
    
    # Define progress bar parameters with user principal name
    $progressParams = @{
        Activity        = "Processing Users"
        Status          = "User $($counter) of $totalUsers - $($user.UserPrincipalName) - $percentComplete% Complete"
        PercentComplete = $percentComplete
    }
    
    Write-Progress @progressParams
    
    # Create an object to store user MFA information
    $myObject = [PSCustomObject]@{
        DisplayName               = "-"
        UserPrincipalName         = "-"
        MFAstatus                 = "Disabled"  # Initialize to "Disabled"
        Email                     = "-"
        Fido2                     = "-"
        MicrosoftAuthenticatorApp = "-"
        Phone                     = "-"
        SoftwareOath              = "-"
        TemporaryAccessPass       = "-"
        WindowsHelloForBusiness   = "-"
    }

    $myObject.UserPrincipalName = $user.UserPrincipalName
    $myObject.DisplayName = $user.DisplayName

    # Check authentication methods for each user
    $MFAData = Get-MgBetaUserAuthenticationMethod -UserId $user.UserPrincipalName

    foreach ($method in $MFAData) {

        Switch ($method.AdditionalProperties["@odata.type"]) {
            "#microsoft.graph.emailAuthenticationMethod" {
                $myObject.Email = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.fido2AuthenticationMethod" {
                $myObject.Fido2 = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.microsoftAuthenticatorAuthenticationMethod" {
                $myObject.MicrosoftAuthenticatorApp = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.phoneAuthenticationMethod" {
                $myObject.Phone = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.softwareOathAuthenticationMethod" {
                $myObject.SoftwareOath = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.temporaryAccessPassAuthenticationMethod" {
                $myObject.TemporaryAccessPass = $true
                $myObject.MFAstatus = "Enabled"
            }
            "#microsoft.graph.windowsHelloForBusinessAuthenticationMethod" {
                $myObject.WindowsHelloForBusiness = $true
                $myObject.MFAstatus = "Enabled"
            }
        }
    }
    
    # Add user object to results array
    $results += $myObject
}

# Export user information to CSV
$results | Export-Csv -Path $Csvfile -NoTypeInformation -Encoding UTF8

Write-Host "Script completed. Results exported to $Csvfile." -ForegroundColor Cyan

将 MFA 状态报告导出为 CSV

导出之前,您需要在 (C:) 驱动器中创建一个名为 temp 的文件夹(如果您还没有)。

要导出所有用户的 MFA 状态报告,您需要以管理员身份运行 PowerShell。

运行 Export-MFAstatus.ps1 PowerShell 脚本。

C:\scripts\.\Export-MFAstatus.ps1

它将连接到 MS Graph,您必须在其中登录您的管理员帐户。

  • 输入密码
  • 点击登录

[玩转系统] 导出所有 Microsoft 365 用户 MFA 状态报告

请求许可以验证同意。

  • 启用代表您的组织同意
  • 点击接受

[玩转系统] 导出所有 Microsoft 365 用户 MFA 状态报告

PowerShell 输出显示一个进度条,让您知道脚本何时完成。它将查找并导出组织中所有用户的 MFA 状态。

Welcome To Microsoft Graph!
Script completed. Results exported to C:\temp\MFAUsers_202309191236.csv.

您可以在 C:\temp 文件夹中找到 CSV 文件。使用 Microsoft Excel 等应用程序打开 CSV 文件以查看结果。

[玩转系统] 导出所有 Microsoft 365 用户 MFA 状态报告

这是我们组织中所有 Microsoft 365 用户 MFA 状态的最终结果。如果用户具有MFA 状态已禁用,则他们只有密码才能登录,而无需任何其他身份验证方法。

  • 已启用:为用户帐户设置 MFA
  • 已禁用:未为用户帐户设置 MFA

注意:提醒列表中 MFA 状态为“已禁用”的用户帐户配置 MFA。

[玩转系统] 导出所有 Microsoft 365 用户 MFA 状态报告

您是否设法使用 Microsoft Graph PowerShell 导出所有 Microsoft 365 用户 MFA 状态?

了解更多:为 Microsoft 365 用户重置 MFA »

结论

您了解了如何导出所有 Microsoft 365 用户 MFA 状态报告。使用 Microsoft Graph PowerShell,您可以运行 Export-MFAstatus.ps1 PowerShell 脚本将每个用户的 MFA 状态导出到 CSV 文件。此报告显示哪些用户启用了 MFA 以及他们使用哪些身份验证方法。

您喜欢这篇文章吗?您可能还喜欢使用 CSV 文件批量创建 Azure AD 用户。不要忘记关注我们并分享这篇文章。

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

取消回复欢迎 发表评论:

关灯