powershell - 通过 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"
解决方案
我找到了自己的答案
此代码仅禁用 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"
推荐阅读
- javascript - 如何在 HTML 表格中显示此 XML 数据?
- mysql - 多张表查询累计和
- c# - 如何从另一个脚本 C# 更改布尔值
- django-models - 如何在 Wagtail 的侧面菜单部分中生成页面列表?
- c# - 输入对于 RSA 密码来说太大 - 我需要一个可用的内存中替代 openssl cms 解密
- docker - 如何根据内存使用情况监控和重新启动在 Docker 中运行的应用程序?
- python - How to create a custom exception?
- plugins - 如何通过下拉列表中的选定选项显示 componentProperties 选项?
- php - 为什么这个函数返回空数据?
- laravel - 如何在不同的命名约定上使用 laravel 进行预加载