[玩转系统] 如何更改 Microsoft 365 用户默认 MFA 方法
作者:精品下载站 日期:2024-12-14 05:51:48 浏览:14 分类:玩电脑
如何更改 Microsoft 365 用户默认 MFA 方法
Microsoft 365 用户应使用 Microsoft Authenticator 应用进行双因素身份验证 (2FA),因为它可以防止基于密码的攻击。在 Microsoft Entra ID 中,您可以更新单个用户的默认多重身份验证 (MFA) 方法。但是,如果您想一次为所有用户设置默认 MFA,该怎么办?在本文中,您将了解如何使用 PowerShell 更改所有用户的默认 MFA 方法。
Microsoft 365 多重身份验证
用户可以使用用户名和密码登录其 Microsoft 帐户。然而,密码应该有一个额外的保护层和更安全的身份验证方法。与用户登录时仅使用密码相比,Microsoft 多重身份验证增加了额外的安全性。
为组织启用不同的身份验证方法后,每个用户都可以选择自己喜欢的 MFA 方法。用户必须提供额外的验证,例如批准推送通知、从软件或硬件令牌输入代码,或者回复短信或电话。
如果组织决定对所有用户使用默认身份验证方法,您可以通过两种方式进行更改:
- Microsoft Entra ID(单用户)
- Microsoft Graph PowerShell(单个和所有用户)
更改 Microsoft Entra 中的默认身份验证方法
要更改 Microsoft Entra ID 中单个用户的默认登录方法,请按照下列步骤操作:
- 登录 Microsoft Entra 管理中心
- 展开身份 > 用户 > 所有用户
- 点击用户
- 点击身份验证方法
- 单击警报标志中的箭头 > 单击此处立即使用
- 检查默认登录方法的铅笔图标是否未灰显
注意:如果默认登录方法(预览)呈灰色,则用户没有默认 MFA 或只有一种登录方法。因此,用户需要添加另一种身份验证方法。
- 点击默认登录方法(预览)旁边的铅笔图标
- 选择默认登录方法(Microsoft Authenticator 通知)
- 点击保存
注意:更改用户的默认 MFA 不会删除其他身份验证方法。如果用户有多种身份验证方法,则在默认方法之后,其他方法将成为次要方法。
您已成功更改 Microsoft Entra ID 中单个 Microsoft 365 用户的默认 MFA。
如果您在单击保存按钮后收到错误通知,请检查身份验证方法策略并查看它是否在 Microsoft Entra ID 中启用。请参阅将旧版 MFA 和 SSPR 迁移到身份验证方法策略一文的第一部分。
无法保存默认登录方法:无法将语音通话(主要移动设备)保存为默认登录方法。 - 未为此用户启用身份验证方法策略。无法更新 UserPreferredMethodForSecondaryAuthentication。
如果需要更改多个 Microsoft 365 用户的身份验证方法以加快该过程,请在下一步中使用 PowerShell。
使用 PowerShell 更改默认 MFA 方法
假设某个组织决定为所有 Microsoft 365 用户使用不同的默认登录方法。因此,使用 PowerShell 脚本更加容易和快捷。
多重身份验证 (MFA) 方法
下表显示了您可以为用户设置的身份验证方法。您必须在后续步骤的 PowerShell 脚本中指定默认方法并使用正确的 MFA 缩写。
Microsoft Authenticator notification on app推
OATH TOTP (6-digit) one-time code on a third-party software app誓言
SMS (6-digit) code as a text message on primary mobile短信
Voice call on the office phone语音替代移动
Voice call on primary mobile语音移动
Voice call on the office phone语音办公室
连接到 Microsoft Graph PowerShell
在开始之前,必须安装 Microsoft Graph PowerShell 模块,包括 Microsoft Graph Beta 模块。
运行以下命令来安装 Microsoft Graph 模块。
Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force
重要提示:始终安装 Microsoft Graph PowerShell 和 Microsoft Graph Beta PowerShell 模块。这是因为某些 cmdlet 在最终版本中尚不可用,并且无法运行。在运行 cmdlet 或脚本之前将两个模块更新到最新版本,以防止出现错误和不正确的结果。
您还需要使用以下范围连接到 MS Graph。
Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.ReadWrite.All"
更改单用户的默认 MFA 方法
要更改单个 Microsoft 365 用户的默认 MFA 方法,请使用以下 PowerShell 脚本:
- 在第 5 行中输入用户的 UserPrincipalName
- 在第 8 行中指定首选 MFA 方法
- 运行以下 PowerShell 脚本
# Connect to Microsoft Graph using the specified authentication scopes
Connect-MgGraph -Scopes "UserAuthenticationMethod.ReadWrite.All", "User.Read.All"
# Specify the user for whom you want to update the preferred method
$UserUPN = "[email protected]"
# Set the desired value for the preferred method
$PreferredMethod = "push"
# Get the user from Microsoft Graph
$User = Get-MgUser -UserId $UserUPN
# Create a JSON body template for the API request
$body = @{
userPreferredMethodForSecondaryAuthentication = $PreferredMethod
}
# Construct the API endpoint URL for getting the user's authentication sign-in preferences
$uri = "https://graph.microsoft.com/beta/users/$($User.Id)/authentication/signInPreferences"
# Send a GET request to the API endpoint to check the user's preferred method
$Check = Invoke-MgGraphRequest -uri $uri -Method GET -OutputType PSObject
# Check if the user already has the preferred method set
if ($Check.userPreferredMethodForSecondaryAuthentication -eq $PreferredMethod) {
Write-host "Default MFA method $PreferredMethod already set for $($User.UserPrincipalName)" -ForegroundColor Cyan
}
else {
try {
# Send a PATCH request to update the user's preferred method
Invoke-MgGraphRequest -uri $uri -Body $body -Method PATCH -ErrorAction Stop
Write-host "Default MFA method $PreferredMethod updated successfully for $($User.UserPrincipalName)" -ForegroundColor Green
}
catch {
# The registered method is not found for the user
Write-Host "Default MFA method $PreferredMethod is not registered by $($User.UserPrincipalName)" -ForegroundColor Yellow
}
}
PowerShell 输出结果显示以下三种不同结果之一:
Default MFA method push already set for [email protected]
Default MFA method push updated successfully for [email protected]
Default MFA method push is not registered by [email protected]
如果未注册MFA方法,则意味着用户需要先添加身份验证方法。
更改所有用户的默认 MFA 方法
要更新组织中所有用户的身份验证方法,我们需要使用 PowerShell 脚本。
在我们的示例中,我们希望将 Microsoft Authenticator 设置为所有用户的默认方法,因为它比发送短信或接听电话更安全。
运行下面的 PowerShell 脚本以更改所有用户的默认 MFA 方法:
- 在第 5 行中指定首选 MFA 方法
- 在第 6 行上指定 CSV 文件的路径
# Connect to Microsoft Graph using the specified authentication scopes
Connect-MgGraph -Scopes "UserAuthenticationMethod.ReadWrite.All", "User.Read.All"
# Set the desired value for the preferred method and the CSV file path
$PreferredMethod = "push"
$CsvPath = "C:\temp\MFAMethodReport.csv"
# Get all users from Microsoft Graph
$AllUsers = Get-MgUser -All
# Create a JSON body template for the API request
$body = @{
userPreferredMethodForSecondaryAuthentication = $PreferredMethod
}
# Create an empty array to store the results
$results = @()
# Loop through each user
foreach ($User in $AllUsers) {
# Construct the API endpoint URL for getting the user's authentication sign-in preferences
$uri = "https://graph.microsoft.com/beta/users/$($User.Id)/authentication/signInPreferences"
# Send a GET request to the API endpoint to check the user's preferred method
$Check = Invoke-MgGraphRequest -uri $uri -Method GET -OutputType PSObject
# Check if the user already has the preferred method set
if ($Check.userPreferredMethodForSecondaryAuthentication -eq $PreferredMethod) {
# Skip the user and add the result to the array
Write-host "Default MFA method $PreferredMethod already set for $($User.UserPrincipalName)" -ForegroundColor Cyan
$result = [PSCustomObject]@{
DisplayName = $User.DisplayName
UserPrincipalName = $User.UserPrincipalName
Status = "Already set"
}
$results += $result
continue
}
try {
# Send a PATCH request to update the user's preferred method
Invoke-MgGraphRequest -uri $uri -Body $body -Method PATCH -ErrorAction Stop
$result = [PSCustomObject]@{
DisplayName = $User.DisplayName
UserPrincipalName = $User.UserPrincipalName
Status = "Updated"
}
$results += $result
Write-host "Default MFA method $PreferredMethod updated successfully for $($User.UserPrincipalName)" -ForegroundColor Green
}
catch {
# The registered method is not found for the user
Write-Host "Default MFA method $PreferredMethod is not registered by $($User.UserPrincipalName)" -ForegroundColor Yellow
$result = [PSCustomObject]@{
DisplayName = $User.DisplayName
UserPrincipalName = $User.UserPrincipalName
Status = "Method not registered"
}
$results += $result
}
}
# Export the results to a CSV file
$results | Export-Csv -Path $csvPath -Encoding utf8 -NoTypeInformation
Write-Host "Results saved to $($CsvPath)" -ForegroundColor Cyan
最后,您将获得一个 CSV 文件报告,其中显示所有用户的状态,默认方法为:
- 已设置
- 已更新
- 未注册
CSV 文件显示更新 MFA 方法失败的用户。如果结果显示未注册,则表示用户尚未设置您指定的默认方法(Microsoft Authenticator)。下一步是向这些用户发送电子邮件,以便他们可以添加身份验证方法。几天后,您可以再次运行该脚本。
转到 C:\temp 并使用 Microsoft Excel 打开 MFAMethodReport.csv 文件。
就是这样。
了解更多:如何提高 Microsoft Entra MFA 安全性 »
结论
您了解了如何更改所有用户的默认 MFA 方法。在 Microsoft Entra 管理中心中,您只能更新单个用户的默认登录。使用 PowerShell 并更改所有用户的默认身份验证方法要快得多。当您更新所有用户的 MFA 方法时,它会将默认身份验证方法状态导出到 CSV 文件报告。它显示哪些用户已设置、更新或未注册 MFA 方法。
您喜欢这篇文章吗?您还可以在 Microsoft Entra 中配置条件访问策略。不要忘记关注我们并分享这篇文章。
猜你还喜欢
- 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