[玩转系统] 如何从 Microsoft Entra 获得 MFA 状态
作者:精品下载站 日期:2024-12-14 06:32:08 浏览:15 分类:玩电脑
如何从 Microsoft Entra 获得 MFA 状态
当您启用安全默认值或启用每用户 MFA 时,您有时需要检查他们是否为多重身份验证配置了以及配置了什么。他们使用哪些方法,是否可以使用无密码登录等。
现在可以在 Microsoft Entra 中查看为用户配置的 MFA 方法。我们还可以查看哪些方法最常用,当然还有哪些用户尚未配置 MFA。
在本文中,我们将了解 Microsoft Entra 中的内置报告功能,并向您展示如何使用 PowerShell 轻松将信息导出到 Excel 文件。
微软 Entra MFA 报告
Microsoft 正在从每用户 MFA 配置转向条件访问策略。这样,您就可以更好地控制用户何时需要使用 MFA 登录、何时不需要。但要配置条件访问策略,您需要拥有 Azure P1 或 P2 许可证。
笔记
要使用本文中的功能,您需要拥有 Azure P1 或 P2 许可证,没有它,您将无法查看 MFA 报告或使用 PowerShell 导出数据。查看本文反而
因此,在启用条件访问策略之前,最好检查用户当前使用的 MFA 方法。您可能希望采用无密码身份验证,但要做到这一点,您的用户需要配置正确的方法。
要查看 Microsoft Entra 中注册的方法,您需要导航到“身份验证方法”报告:
打开 Microsoft Entra 管理中心
展开保护
打开身份验证方法
点击用户注册详细信息
例如,您可以使用页面顶部的筛选选项来查看没有 MFA 的用户或未配置自助密码重置 (SSPR) 的用户。
“活动”页面将为您提供一些最常用方法的概述,以及一些没有 MFA 的用户百分比的统计数据。
使用 PowerShell 获取 Entra MFA 状态
我之前创建过 PowerShell 脚本,用于使用 PowerShell 获取用户的 MFA 状态。如果您没有 Azure P1 或 P2 许可证,则可以使用此脚本获取状态。
本文中的脚本将使用 Microsoft Graph 从 Microsoft Entra 获取 MFA 状态。此报告的优点是它将获取默认方法、显示所有已注册的方法以及用户是否具有 MFA 和无密码功能。
笔记
要获得默认方法,您需要使用 beta 模块。确保您还安装了测试版模块:Install-Module Microsoft.Graph.Beta -AllowClobber -Force
要获取与 Microsoft Entra 中看到的完全相同的数据,您只需使用 cmdlet Get-MgReportAuthenticationMethodUserRegistrationDetail
即可。值得一提的是,此 cmdlet 将仅返回已启用的帐户。
您需要安装 Microsoft Graph PowerShell 模块并使用 Reports.Read.All
范围连接到 Graph:
# 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
。仅导出没有 MFA 的用户UserPrincipalName -
<string>
。允许您指定要检索的用户主体名称
该脚本将首先获取所有报告数据,然后过滤掉请求的用户。从技术上讲,也可以只获取选定用户的报告数据,但事实证明这比先获取所有数据要慢得多。
为了获取用户,我们将向 Microsoft Graph 发出单独的请求,以获取应用了筛选器的用户。如果您查看脚本中的 Get-Users 函数,您将看到一个 Select 数组。这些是包含在导出中的属性。您可以根据需要扩展此列表,例如,获取部门信息或用户的职位。
该脚本会将以下数据导出到 CSV 文件:
显示名称
电子邮件地址
用户主体名称
用户类型(会员或访客)
是管理员
支持 MFA(如果为 true,则用户已配置 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://a-d.site
#>
[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,我们可以包含联系方式详细信息、用户经理或部门详细信息,这些信息非常有帮助。
我希望您喜欢这篇文章和脚本,如果您有任何疑问,请在下面发表评论。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag