因此,我正在尝试提出一种可靠的方法,以确定用户在运行脚本之前是否已在其帐户上配置了o365多因素身份验证,以使他们不会重新启用。
使用:
$MFAUsers = Get-Msoluser -userprincipalname test.webjea@xxx.com | select "StrongAuthenticationRequirements"
输出(如果已启用)
StrongAuthenticationRequirements
--------------------------------
{Microsoft.Online.Administration.StrongAuthenticationRequirement}
以及以下内容(如果已禁用)
StrongAuthenticationRequirements
--------------------------------
{}
理想情况下,如果用户被禁用,则脚本将针对启用该脚本的帐户运行。如果启用它们,脚本将跳过它们。 为了进行测试,我已草拟
if ($MFAUsers -eq "{Microsoft.Online.Administration.StrongAuthenticationRequirement}") {
"NO MFA"
}
Elseif ($MFAUsers -eq "{Microsoft.Online.Administration.StrongAuthenticationRequirement}"){
"MFA"
}
针对已启用的测试帐户运行此命令时,我仍然收到“无MFA”响应
有人知道吗?我敢肯定这是愚蠢的,但是我真的不能把手放在上面吗?是否看到“ StrongAuthenticationRequirments”标头?
答案 0 :(得分:1)
if
和elseif
所做的测试相同。
返回{Microsoft.Online.Administration.StrongAuthenticationRequirement}
时,表示已为该用户启用了MFA。函数返回{}
时,用户未设置StrongAuthenticationRequirement。
我自己无法测试,但是运行以下代码应该向您显示哪些用户启用了“ MFA”,哪些用户未启用。
# test for all users would be Get-MsolUser -All
Get-MsolUser -UserPrincipalName 'test.webjea@xxx.com' |
Select-Object DisplayName, UserPrincipalName,
@{ Name = "MFA"
Expression = {
if($_.StrongAuthenticationRequirements.Count -ne 0) {
$_.StrongAuthenticationRequirements[0].State
}
else { 'Disabled' }
} }