为 Azure/Microsoft 365 中的用户启用或禁用 MFA
您可以使用 Azure 门户、Microsoft 365 管理中心或 PowerShell 为 Azure/Microsoft 365 租户中的用户启用、禁用或获取多重身份验证 (MFA) 状态。在本文中,我们将展示如何在 AzureAD 中管理用户帐户的 MFA 并获取有关用户使用的第二个因素的报告。
我们假设您基于每个用户管理 MFA,而不是使用 Azure 条件访问策略。
您可以通过两种方式访问所有用户具有 MFA 状态的网页:
Microsoft 365 管理中心 -> 活动用户 -> 多重身份验证。
门户 Azure -> Azure AD-> 用户 -> 每用户 MFA
您将看到租户中所有用户的列表以及每个用户的 MFA 状态。可用的 MFA 状态有:
您可以使用右侧快速步骤面板中的按钮为每个用户启用、禁用、重置或配置 MFA。
该报告不会显示用户是否完成了 MFA 设置以及他选择了哪个第二因素。此外,您无法将页面内容导出到 TXT/CSV 文件。使用 PowerShell 更轻松地管理 Microsoft 365 中的用户 MFA 并构建报告。
现在,你可以使用 MSOnline 模块或 Microsoft Graph API 在 PowerShell 中为 Azure (Microsoft 365) 用户启用/禁用 MFA。
目前无法使用最新版本的 AzureAD 模块管理 MFA。
安装 MSOnline 模块(如果需要)并连接到您的租户:
Install-Module MSOnline
Connect-MsolService您可以从以下位置获取有关用户 MFA 状态的信息
StrongAuthenticationMethods属性:
Get-MsolUser -UserPrincipalName t.muller@a-d.onmicrosoft.com | Select-Object UserPrincipalName,StrongAuthenticationMethods如果 StrongAuthenticationMethods 属性不为空,则为用户启用 MFA。您可以了解为用户配置的 MFA 类型:
(Get-MsolUser -UserPrincipalName t.muller@a-d.onmicrosoft.com). StrongAuthenticationMethods下面的屏幕截图显示用户已启用 Microsoft Authenticator 应用程序作为第二个 MFA 因素(PhoneAppNotification -
IsDefault=True)。
Microsoft 现代身份验证允许四种类型的身份验证作为用户的第二个因素:
OneWaySMS - 标准短信;
TwoWayVoiceMobile - 用户在通话中获得一次性密码;
-
PhoneAppOTP - 用户使用硬件令牌或 Microsoft Authenticator 应用程序获取一次性密码(6 个数字字符);
PhoneAppNotification - 使用 Microsoft Authenticator 应用进行身份验证。
为 Azure 用户启用 MFA:
$st = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
$st.RelyingParty = "*"
$st.State = "Enabled"
$sta = @($st)
Set-MsolUser -UserPrincipalName t.muller@a-d.onmicrosoft.com -StrongAuthenticationRequirements $sta要强制用户更改其当前的 MFA 方法:
Set-MsolUser -UserPrincipalName t.muller@a-d.onmicrosoft.com -StrongAuthenticationMethods @()要为用户禁用 MFA:
Get-MsolUser -UserPrincipalName t.muller@a-d.onmicrosoft.com | Set-MsolUser -StrongAuthenticationRequirements @()您可以使用以下 PowerShell 脚本获取 Azure 租户中所有用户的 MFA 状态:
$Report = @()
$AzUsers = Get-MsolUser -All
ForEach ($AzUser in $AzUsers) {
$DefaultMFAMethod = ($AzUser.StrongAuthenticationMethods | ? { $_.IsDefault -eq "True" }).MethodType
$MFAState = $AzUser.StrongAuthenticationRequirements.State
if ($MFAState -eq $null) {$MFAState = "Disabled"}
$objReport = [PSCustomObject]@{
User = $AzUser.UserPrincipalName
MFAState = $MFAState
MFAPhone = $AzUser.StrongAuthenticationUserDetails.PhoneNumber
MFAMethod = $DefaultMFAMethod
}
$Report += $objReport
}
$Report您可以将 MFA 报告导出到 CSV 文件:
$Report| Export-CSV -NoTypeInformation -Encoding UTF8 c:\Reports\AzureUsersMFAstatus.csv或者进入 Out-GridView 表:
$Report | Out-GridView该脚本可在我的 GitHub 存储库中找到:https://github.com/maxbakhub/winposh/blob/main/Azure/GetAzureMFAUsersReport.ps1



