วิธีรับสถานะ MFA จาก Microsoft Entra
เมื่อคุณเปิดใช้งานค่าเริ่มต้นความปลอดภัยหรือเปิดใช้งาน MFA ต่อผู้ใช้ ในบางจุดคุณต้องการตรวจสอบว่าพวกเขาได้กำหนดค่าไว้สำหรับการรับรองความถูกต้องแบบหลายปัจจัยหรือไม่และสิ่งที่พวกเขาได้กำหนดค่าไว้ พวกเขาใช้วิธีการใด พวกเขาสามารถใช้การลงชื่อเข้าใช้แบบไร้รหัสผ่านได้หรือไม่ ฯลฯ
ตอนนี้คุณสามารถดูวิธี MFA ที่กำหนดค่าสำหรับผู้ใช้ของคุณใน Microsoft Entra ได้แล้ว นอกจากนี้เรายังสามารถดูวิธีการที่ใช้มากที่สุดและแน่นอนว่าผู้ใช้รายใดที่ยังไม่ได้กำหนดค่า MFA
ในบทความนี้ เราจะดูคุณลักษณะการรายงานในตัวใน Microsoft Entra และฉันจะแสดงให้คุณเห็นว่าคุณสามารถส่งออกข้อมูลด้วย PowerShell ไปยังไฟล์ Excel ได้อย่างง่ายดายได้อย่างไร
รายงาน MFA ของ Microsoft Entra
Microsoft กำลังย้ายจากการกำหนดค่า MFA ต่อผู้ใช้ไปเป็นนโยบายการเข้าถึงแบบมีเงื่อนไข ด้วยวิธีนี้ คุณจะสามารถควบคุมได้มากขึ้นว่าเมื่อใดที่ผู้ใช้จำเป็นต้องลงชื่อเข้าใช้ด้วย MFA และเมื่อไม่ต้องการ แต่ในการกำหนดค่านโยบายการเข้าถึงแบบมีเงื่อนไข คุณจะต้องมีสิทธิ์การใช้งาน Azure P1 หรือ P2
บันทึก
หากต้องการใช้ฟีเจอร์ในบทความนี้ คุณจะต้องมีสิทธิ์การใช้งาน Azure P1 หรือ P2 หากไม่มี คุณจะไม่สามารถดูรายงาน MFA หรือส่งออกข้อมูลด้วย PowerShell ได้
ชำระเงินบทความนี้ แทน
ดังนั้นก่อนที่คุณจะเปิดใช้งานนโยบายการเข้าถึงแบบมีเงื่อนไข คุณควรตรวจสอบว่าผู้ใช้ของคุณใช้วิธี MFA ใดอยู่ในปัจจุบัน คุณอาจต้องการเปลี่ยนมาใช้การตรวจสอบสิทธิ์แบบไม่ใช้รหัสผ่าน แต่ในการดำเนินการนี้ ผู้ใช้ของคุณจะต้องกำหนดค่าวิธีการที่ถูกต้อง
หากต้องการดูวิธีการลงทะเบียนใน Microsoft Entra คุณจะต้องไปที่รายงานวิธีการรับรองความถูกต้อง:
เปิดศูนย์การจัดการ Microsoft Entra
ขยาย การป้องกัน
เปิดวิธีการตรวจสอบสิทธิ์
คลิกที่ รายละเอียดการลงทะเบียนผู้ใช้
คุณสามารถใช้ตัวเลือกตัวกรองที่ด้านบนของหน้าเพื่อดูผู้ใช้ที่ไม่มี MFA หรือผู้ใช้ที่ไม่ได้กำหนดค่าการรีเซ็ตรหัสผ่านด้วยตนเอง (SSPR) เป็นต้น
หน้ากิจกรรมจะให้ภาพรวมที่ดีของวิธีการที่ใช้บ่อยที่สุด และสถิติบางส่วนของเปอร์เซ็นต์ของผู้ใช้ที่ไม่มี MFA เป็นต้น
รับสถานะ Entra MFA ด้วย PowerShell
ฉันได้สร้างสคริปต์ PowerShell มาก่อนเพื่อรับสถานะ MFA ของผู้ใช้ของคุณด้วย PowerShell หากคุณไม่มีใบอนุญาต Azure P1 หรือ P2 คุณสามารถใช้สคริปต์นี้เพื่อรับสถานะได้
สคริปต์ในบทความนี้จะได้รับสถานะ MFA จาก Microsoft Entra โดยใช้ Microsoft Graph ข้อดีของรายงานนี้คือจะได้รับวิธีการเริ่มต้น แสดงวิธีการที่ลงทะเบียนไว้ทั้งหมด และดูว่าผู้ใช้มีความสามารถ MFA และไม่ใช้รหัสผ่านหรือไม่
บันทึก
หากต้องการรับวิธีการเริ่มต้น คุณจะต้องใช้โมดูลเบต้า ตรวจสอบให้แน่ใจว่าคุณได้ติดตั้งโมดูลเบต้าด้วย:Install-Module Microsoft.Graph.Beta -AllowClobber -Force
หากต้องการรับข้อมูลเดียวกันกับที่คุณเห็นใน Microsoft Entra คุณสามารถใช้ cmdlet Get-MgReportAuthenticationMethodUserRegistrationDetail สิ่งที่น่ารู้ก็คือ cmdlet นี้จะส่งคืนบัญชีที่เปิดใช้งานเท่านั้น
คุณจะต้องติดตั้งโมดูล Microsoft Graph PowerShell และเชื่อมต่อกับ Graph ด้วยขอบเขต Reports.Read.All:
# Connect to Graph
Connect-MgGraph -Scopes "Reports.Read.All"
# Get all report data
# Note, we are using the beta module here, so we can get the default method as well
Get-MgBetaReportAuthenticationMethodUserRegistrationDetailสคริปต์ที่สมบูรณ์
ฉันได้สร้างสคริปต์ที่ช่วยให้คุณควบคุมผู้ใช้ที่คุณต้องการรวมไว้ในการส่งออกได้มากขึ้นอีกเล็กน้อย ตัวอย่างเช่น ฉันมักจะต้องการตรวจสอบเฉพาะผู้ใช้ที่ได้รับใบอนุญาตเท่านั้น หรือตรวจสอบวิธีการ MFA ของผู้ดูแลระบบอย่างรวดเร็ว
คุณสามารถใช้พารามิเตอร์ต่อไปนี้เพื่อกรองผลลัพธ์:
ผู้ดูแลระบบเท่านั้น -
$true หรือ $falseจะส่งออกเฉพาะผู้ใช้ที่มีบทบาทผู้ดูแลระบบเท่านั้นได้รับอนุญาต -
จริง เท็จ ทั้งสองรวมเฉพาะผู้ใช้ที่ได้รับใบอนุญาต ไม่มีใบอนุญาต หรือผู้ใช้ทั้งหมดwithOutMFAOnly -
$true หรือ $falseส่งออกเฉพาะผู้ใช้ที่ไม่มี MFAUserPrincipalName - <รหัส>
ช่วยให้คุณสามารถระบุชื่อผู้ใช้หลักที่จะดึงข้อมูล
สคริปต์จะได้รับข้อมูลรายงานทั้งหมดก่อน จากนั้นจึงกรองผู้ใช้ที่ร้องขอออก ในทางเทคนิคแล้ว อาจเป็นไปได้เช่นกันที่จะรับเฉพาะข้อมูลรายงานจากผู้ใช้ที่เลือก แต่กลับกลายเป็นว่าช้ากว่าการรับข้อมูลทั้งหมดก่อนมาก
ในการรับผู้ใช้ เราจะส่งคำขอแยกต่างหากไปยัง Microsoft Graph เพื่อให้ผู้ใช้ได้รับตัวกรองที่ใช้ หากคุณดูฟังก์ชัน Get-Users ในสคริปต์ คุณจะเห็นอาร์เรย์ Select เหล่านี้เป็นคุณสมบัติที่รวมอยู่ในการส่งออก คุณสามารถขยายรายการนี้ตามความต้องการของคุณได้ เช่น เพื่อรับข้อมูลแผนกหรือตำแหน่งงานของผู้ใช้
สคริปต์จะส่งออกข้อมูลต่อไปนี้เป็นไฟล์ CSV:
ชื่อที่แสดง
ที่อยู่อีเมล
UserPrincipalName
ประเภทผู้ใช้ (สมาชิกหรือแขก)
คือผู้ดูแลระบบ
MFA Capable (เมื่อเป็นจริง แสดงว่าผู้ใช้ได้กำหนดค่า MFA แล้ว)
วิธีการเริ่มต้นของ MFA
MFA วิธีรอง
วิธีการลงทะเบียน MFA
โดยไม่ต้องใช้รหัสผ่าน
SSPR ลงทะเบียนแล้ว
SSPR มีความสามารถ
ผู้จัดการของผู้ใช้
คุณสามารถรับสคริปต์เวอร์ชันล่าสุดได้ที่นี่จากที่เก็บ Github ของฉัน หากต้องการเรียกใช้สคริปต์ ให้บันทึกไฟล์ลงในไดเร็กทอรีงานของคุณ และเรียกใช้สคริปต์ด้วยพารามิเตอร์ทางเลือกใน PowerShell อ่านเพิ่มเติมเกี่ยวกับการเรียกใช้สคริปต์ PowerShell ในบทความนี้
<#
.Synopsis
Get the MFA status for all users, admin or selected users from Microsoft Entra
.DESCRIPTION
This script will get the Azure MFA Status for your users. You can query all the users, admins only or a single user.
It will return the MFA Status, MFA type, Default method, SSRP, and registered devices.
.NOTES
Name: Get-MgEntraMFAStatus
Author: R. Mens - LazyAdmin.nl
Version: 1.2
DateCreated: Feb 2024
Purpose/Change: Fixed licensed and enabled users
.LINK
https://lazyadmin.nl
#>
[CmdletBinding(DefaultParameterSetName="Default")]
param(
[Parameter(
Mandatory = $false,
ParameterSetName = "UserPrincipalName",
HelpMessage = "Enter a single UserPrincipalName or a comma separted list of UserPrincipalNames",
Position = 0
)]
[string[]]$UserPrincipalName,
[Parameter(
Mandatory = $false,
ValueFromPipeline = $false,
ParameterSetName = "AdminsOnly"
)]
# Get only the users that are an admin
[switch]$adminsOnly = $false,
[Parameter(
Mandatory = $false,
ValueFromPipeline = $false,
ParameterSetName = "allUsers"
)]
[Alias("Licensed")]
[ValidateSet("true", "false", "both")]
# Check only the MFA status of users that have license
[string]$IsLicensed = 'true',
[Parameter(
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = "allUsers"
)]
# Get only the users that don't have MFA enabled
[switch]$withOutMFAOnly = $false,
[Parameter(
Mandatory = $false,
HelpMessage = "Enter path to save the CSV file"
)]
[string]$CSVPath = ".\EntraMFAStatus-$((Get-Date -format "MMM-dd-yyyy").ToString()).csv"
)
Function ConnectTo-MgGraph {
# Check if MS Graph module is installed
if (-not(Get-InstalledModule Microsoft.Graph)) {
Write-Host "Microsoft Graph module not found" -ForegroundColor Black -BackgroundColor Yellow
$install = Read-Host "Do you want to install the Microsoft Graph Module?"
if ($install -match "[yY]") {
Install-Module Microsoft.Graph -Repository PSGallery -Scope CurrentUser -AllowClobber -Force
}else{
Write-Host "Microsoft Graph module is required." -ForegroundColor Black -BackgroundColor Yellow
exit
}
}
# Connect to Graph
Write-Host "Connecting to Microsoft Graph" -ForegroundColor Cyan
Connect-MgGraph -Scopes "Reports.Read.All" -NoWelcome
}
Function Get-Admins{
<#
.SYNOPSIS
Get all user with an Admin role
#>
process{
$admins = Get-MgDirectoryRole | Select-Object DisplayName, Id |
%{$role = $_.DisplayName; Get-MgDirectoryRoleMember -DirectoryRoleId $_.id |
where {$_.AdditionalProperties."@odata.type" -eq "#microsoft.graph.user"} |
% {Get-MgUser -userid $_.id }
} |
Select @{Name="Role"; Expression = {$role}}, DisplayName, UserPrincipalName, Mail, Id | Sort-Object -Property Mail -Unique
return $admins
}
}
Function Get-Users {
# Set the properties to retrieve
$select = @(
'mail'
'userprincipalname'
'displayname'
)
$properties = $select + "AssignedLicenses"
# Get-MgBetaReportAuthenticationMethodUserRegistrationDetail returns only enabled accounts
# so we get only enabled accounts here as well.
$filter = "AccountEnabled eq true and UserType eq 'member'"
# Check if UserPrincipalName(s) are given
if ($UserPrincipalName) {
Write-host "Get specific users" -ForegroundColor Cyan
$users = @()
foreach ($user in $UserPrincipalName)
{
try {
$users += Get-MgUser -UserId $user -Property $properties | select $select -ErrorAction Stop
}
catch {
[PSCustomObject]@{
DisplayName = " - Not found"
UserPrincipalName = $User
isAdmin = $null
MFAEnabled = $null
}
}
}
}elseif($adminsOnly) {
Write-host "Get admins only" -ForegroundColor Cyan
$users = @()
foreach ($admin in $admins) {
$users += Get-MgUser -UserId $admin.UserPrincipalName -Property $properties | select $select
}
}else{
if ($IsLicensed -eq 'true') {
# Get only licensed users
$users = Get-MgUser -Filter $filter -Property $properties -all | Where-Object {($_.AssignedLicenses).count -gt 0} | select $select
}elseif ($IsLicensed -eq 'false') {
# Get only users without license
$users = Get-MgUser -Filter $filter -Property $properties -all | Where-Object {($_.AssignedLicenses).count -eq 0} | select $select
}else{
$users = Get-MgUser -Filter $filter -Property $properties -all | select $select
}
}
return $users
}
Function Get-Manager {
<#
.SYNOPSIS
Get the manager users
#>
param(
[Parameter(Mandatory = $true)] $userId
)
process {
$manager = Get-MgUser -UserId $userId -ExpandProperty manager | Select @{Name = 'name'; Expression = {$_.Manager.AdditionalProperties.displayName}}
return $manager.name
}
}
Function Get-MFAStatusUsers {
<#
.SYNOPSIS
Get all AD users
#>
process {
Write-Host "Collecting users" -ForegroundColor Cyan
# Collect users to get
$users = Get-Users
# Get all MFA Report data
$reportData = Get-MgBetaReportAuthenticationMethodUserRegistrationDetail
Write-Host "Processing" $users.count "users" -ForegroundColor Cyan
# Collect and loop through all users
foreach ($reportUser in $reportData) {
# Check if we want this users in the output
# Note - it's faster to get all report data and then filter it on the selected users,
# then getting the report data for each individual user
if ($reportUser.UserPrincipalName -notin $users.UserPrincipalName) {
continue
}
Write-Host "- Processing $($reportUser.UserDisplayName)" -ForegroundColor Cyan
# Get the user data from the users array
$userData = $users | where-object {$_.UserPrincipalName -eq $reportUser.UserPrincipalName}
# Get the manager of the user (optional)
$manager = Get-Manager -userId $reportUser.id
# Create output object
[pscustomobject]@{
"Name" = $userData.DisplayName
"Emailaddress" = $userData.mail
"UserPrincipalName" = $reportUser.UserPrincipalName
"User Type" = $reportUser.UserType
"isAdmin" = $reportUser.IsAdmin
"MFA Capable" = $reportUser.IsMfaCapable
"MFA Default method" = $reportUser.DefaultMfaMethod
"MFA Secondary method" = $reportUser.UserPreferredMethodForSecondaryAuthentication
"MFA Methods Registered" = $reportUser.MethodsRegistered -join ", "
"Passwordless Capable" = $reportUser.IsPasswordlessCapable
"SSPR Registered" = $reportUser.IsSsprRegistered
"SSPR Capable" = $reportUser.IsSsprCapable
"Manager" = $manager
}
}
}
}
# Connect to Graph
ConnectTo-MgGraph
# Get Admins
# Get all users with admin role
$admins = $null
if ($adminsOnly) {
$admins = Get-Admins
}
# Get MFA Status
Get-MFAStatusUsers | Sort-Object Name | Export-CSV -Path $CSVPath -NoTypeInformation
if ((Get-Item $CSVPath).Length -gt 0) {
Write-Host "Report finished and saved in $CSVPath" -ForegroundColor Green
# Open the CSV file
Invoke-Item $CSVPath
}else{
Write-Host "Failed to create report" -ForegroundColor Red
}ห่อ
การติดตามการกำหนดค่า MFA ของผู้ใช้ของคุณเป็นสิ่งสำคัญเพื่อให้ผู้เช่า Microsoft 3675 ของคุณปลอดภัย รายงานใหม่ใน Microsoft Entra ช่วยให้คุณสามารถติดตามผู้ใช้ที่ไม่ผ่านขั้นตอนการตั้งค่า MFA หรือใช้วิธีการ MFA ที่ล้าสมัยได้อย่างง่ายดาย
แม้ว่ารายงานใน Microsoft Entra จะให้ข้อมูลที่จำเป็นที่สุด แต่ด้วย PowerShell เราสามารถใส่รายละเอียดการติดต่อ ผู้จัดการของผู้ใช้ หรือรายละเอียดแผนกที่อาจเป็นประโยชน์ได้จริงๆ
ฉันหวังว่าคุณจะชอบบทความและสคริปต์นี้ หากคุณมีคำถามใด ๆ เพียงแค่แสดงความคิดเห็นด้านล่าง

