Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save watahani/c3ca032a408a016e90192a4e58506901 to your computer and use it in GitHub Desktop.
Save watahani/c3ca032a408a016e90192a4e58506901 to your computer and use it in GitHub Desktop.
# すべてのユーザーに一括して会社電話番号での MFA を設定する
Get-MsolUser -All | ForEach {
$user = $_
$mfa = $user.StrongAuthenticationMethod
# MFA が何も設定されていない
if (-not $mfa) {
$twoWayOfficeDefaultTrue = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationMethod
$twoWayOfficeDefaultTrue.MethodType = "TwoWayVoiceOffice"
$twoWayOfficeDefaultTrue.IsDefault = $True
$mfa = @($twoWayOfficeDefaultTrue)
}
else {
# MFA が設定されていて
# かつ、TwoWayVoiceOffice が設定されていない場合
if ( -not ($($mfa | Where-Object { $_.MethodType -eq "TwoWayVoiceOffice" })) ) {
$twoWayOffice = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationMethod
$twoWayOffice.MethodType = "TwoWayVoiceOffice"
$twoWayOffice.IsDefault = $False
$mfa += $twoWayOffice
}
}
$mfa
Set-MsolUser -UserPrincipalName $_.UserPrincipalName -StrongAuthenticationMethods $mfa
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment