在 Microsoft Entra 和 PowerShell 中獲取 MFA 狀態

Jacki

您不想使用 PowerShell 列出 Microsoft 365/Microsoft Entra MFA 用戶狀態?相反,您想要使用圖形用戶界面 (GUI)。不用擔心,因為您可以從 Microsoft Entra 管理中心獲取所有 MFA 詳細信息。在本文中,您將了解如何在 Microsoft Entra 和 PowerShell 中獲取 MFA 用戶身份驗證方法。門戶網站。

在 Microsoft 租戶中配置 MFA 有兩種方法:

  1. 配置 MFA 與條件訪問
  2. 配置每用戶 MFA

我們推薦選項1因為您有更多的控制權和更多的功能需要配置。但它需要 Microsoft Entra ID P1 或 Microsoft Entra ID P2 許可證。因此,如果您買不起這些 Entra ID 版本,請選擇免費的選項 2。

在此過程中,請閱讀文章防止組織中的 MFA 疲勞攻擊並啟用所示的設置以提供額外的保護。

重要的:為每個租戶啟用 MFA,因為它至關重要的

假設您有 Microsoft Entra ID P1 或 P2 並配置了每用戶 MFA,但想要遷移到條件訪問 MFA;請閱讀文章從每用戶 MFA 遷移到條件訪問 MFA。

如何在 Microsoft Entra 中獲取所有用戶的 MFA 狀態

按照以下步驟檢查哪些用戶已在 Microsoft Entra 管理中心註冊 MFA:

  1. 登錄到微軟 Entra 管理中心
  2. 擴張身份 > 保護
  3. 點擊認證方式
  4. 選擇用戶註冊詳情

筆記:您需要 Microsoft Entra ID P1 或 P2 許可證才能在 Microsoft Entra 管理中心查看用戶註冊詳細信息。如果沒有,請使用使用 PowerShell 將 Microsoft Entra ID 用戶導出到 CSV 一文中的腳本。

  1. 檢查以下列以獲取 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 腳本

上創建兩個文件夾(中:)駕駛:

  • 溫度
  • 腳本

下載 Get-AuthenticationMethods.ps1 PowerShell 腳本並將其放入C:腳本文件夾。該腳本會將 CSV 文件導出到C:溫度文件夾。

確保文件未被阻止,以防止運行腳本時出現錯誤。請閱讀文章運行 PowerShell 腳本時出現未數字簽名錯誤來了解更多信息。

另一種選擇是將以下代碼複製並粘貼到記事本中。給它起個名字獲取身份驗證方法.ps1並將其放置在C:腳本文件夾。

<#
    .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.alitajran.com/get-mfa-status-entra/

    .NOTES
    Written by: ALI TAJRAN
    Website:    www.alitajran.com
    LinkedIn:   linkedin.com/in/alitajran

    .CHANGELOG
    V1.00, 10/12/2023 - Initial version
    V1.10, 11/04/2024 - Added parameters to script
#>

param (
    [Parameter(Mandatory = $true)]
    [string]$CSVPath,
    [string]$GroupId = ""
)

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

try {
    # If a GroupId is provided, fetch group members first
    if ($GroupId) {
        Write-Host "Fetching members for GroupId: $GroupId" -ForegroundColor Cyan
        $GroupMembers = Get-MgGroupMember -GroupId $GroupId -All
        $GroupMemberIds = $GroupMembers.Id
    }

    # Fetch user registration detail report from Microsoft Graph
    if ($GroupId) {
        $Users = Get-MgBetaReportAuthenticationMethodUserRegistrationDetail -All | Where-Object { $GroupMemberIds -contains $_.Id }
    }
    else {
        $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
}

步驟 2. 安裝 Microsoft Graph PowerShell

以管理員身份運行 Windows PowerShell 並安裝 Microsoft Graph PowerShell。

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

重要的:始終安裝 Microsoft Graph PowerShell 和 Microsoft Graph Beta PowerShell 模塊。這是因為某些 cmdlet 在最終版本中尚不可用,並且它們將無法工作。在運行 cmdlet 或腳本之前將兩個模塊更新到最新版本,以防止出現錯誤和不正確的結果。

步驟 3. 連接到 Microsoft Graph PowerShell

連接到 Microsoft Graph PowerShell。

Connect-MgGraph -Scopes "AuditLog.Read.All", "Group.Read.All"

輸入您的全局管理員憑據並接受 Microsoft Graph 權限請求。

步驟 4. 運行 Get-AuthenticationMethods PowerShell 腳本

使用 PowerShell 獲取所有用戶身份驗證方法。

C:scripts.Get-AuthenticationMethods.ps1 -CSVPath "C:TempAuthenticationReport.csv" 

使用 PowerShell 從組中獲取所有用戶身份驗證方法。在後面添加組的唯一標識符-組ID下面命令中的參數。

C:scripts.Get-AuthenticationMethods.ps1 -CSVPath "C:TempAuthenticationReport.csv" -GroupId "5859108f-0a92-4db3-b779-b9e9f098d4c8"

一個網格視圖將顯示包含所有用戶及其信息的列。

參見:使用 PowerShell 從 CSV 創建 Microsoft Entra ID 用戶

步驟 5. 打開身份驗證方法報告

Get-AuthenticationMethods.ps1 PowerShell 腳本將所有用戶身份驗證方法導出到 CSV 文件。找到文件身份驗證報告.csv在路徑中C:溫度

使用您喜歡的應用程序打開 CSV 文件。在我們的示例中,它是 Microsoft Excel。

就是這樣!

多重身份驗證常見問題解答

會有關於什麼時候狀態的問題有能力的沒有能力出現在列表中的用戶帳戶。以下是您可能有的主要問題及其答案。

有能力和沒有能力有什麼區別?

  • 有能力的:為用戶帳戶設置MFA
  • 沒有能力:未為用戶帳戶設置 MFA

多重身份驗證何時顯示為“可用”?

它將顯示為有能力的如果用戶完成 MFA 嚮導配置。因此只要用戶沒有完成MFA設置,就會顯示為沒有能力

如果您為用戶啟用或強制執行每用戶 MFA,並且用戶未配置 MFA,則它仍顯示為“無法使用”。如果您配置 MFA 條件訪問並將用戶添加到策略中,這同樣適用。如果用戶沒有配置MFA,則顯示為沒有能力

每用戶 MFA 和條件訪問 MFA 是否出現在列表中?

是的,每用戶 MFA 和條件訪問 MFA 用戶及其身份驗證方法將顯示在列表中。

重要的:使用條件訪問啟用 MFA 時,為所有用戶禁用每用戶 MFA。

筆記:對於顯示為的用戶帳戶沒有能力,聯繫用戶並提醒他們完成 MFA 設置嚮導。

結論

您了解瞭如何在 Microsoft Entra 和 PowerShell 中獲得 MFA 狀態。 Microsoft Entra 管理中心中的身份驗證方法部分非常棒。這有助於希望避免使用 PowerShell 獲取 MFA 狀態信息的管理員。

每個用戶都必須配置多重身份驗證,通過查看身份驗證方法中的用戶註冊詳細信息,您可以快速識別使用了哪些 MFA 方法以及哪些人還需要配置 MFA。

您喜歡這篇文章嗎?您可能還喜歡條件訪問 MFA 中斷 Azure AD Connect 同步。不要忘記關注我們並分享這篇文章。