首页 > 解决方案 > 通过 PowerSehll 启用没有旧电话号码的 O365 MFA

问题描述

我创建了 2 x PowerShell 脚本来启用和禁用 MFA,它可以工作,但是当我想删除电话号码时,禁用 MFA 脚本不会删除电话号码。所以当我再次为用户启用 MFA 时。旧号码还在

启用 MFA

Import-Module MSOnline
    $Username = 'o365admin@xxx.onmicrosoft.com'
    $Password = ConvertTo-SecureString 'Password' -AsPlainText -Force
    $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username,$Password -ErrorAction Stop
    Connect-MsolService -credential $credentials -ErrorAction Stop
    $mfa = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement")
    $mfa.RelyingParty = '*'
    $mfa.RememberDevicesNotIssuedBefore = (Get-Date)
    $auth = @($mfa)
Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationRequirements $auth"

禁用 MFA

Import-Module MSOnline
    $Username = 'o365admin@xxx.onmicrosoft.com'
    $Password = ConvertTo-SecureString 'Password' -AsPlainText -Force
    $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username,$Password -ErrorAction Stop
    Connect-MsolService -credential $credentials -ErrorAction Stop
    $mfa = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement")
    $mfa.RelyingParty = '*'
    $mfa.RememberDevicesNotIssuedBefore = (Get-Date)
    $auth = @()
    Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationRequirements $auth"

标签: powershellmulti-factor-authentication

解决方案


我找到了自己的答案

此代码仅禁用 MFA,但不删除电话号码等

Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationRequirements $auth"

我还必须添加它以删除电话号码

Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationMethods $auth"

所以代码看起来像:

Import-Module MSOnline
    $Username = 'o365admin@xxx.onmicrosoft.com'
    $Password = ConvertTo-SecureString 'Password' -AsPlainText -Force
    $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username,$Password -ErrorAction Stop
    Connect-MsolService -credential $credentials -ErrorAction Stop
    $mfa = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement")
    $mfa.RelyingParty = '*'
    $mfa.RememberDevicesNotIssuedBefore = (Get-Date)
    $auth = @()
    Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationMethods $auth"
    Set-MsolUser -UserPrincipalName user@xxx.onmicrosoft.com -StrongAuthenticationRequirements $auth"

推荐阅读