Share via


Ο365: How to enable MFA using PowerShell and CSV File

The steps below show how we can enable MFA to multiple accounts by using a PowerShell script and a CSV file.

Step 1. Create the CSV File

On the first step we need to create a csv file with the column "UserPrincipalName

UserPrincipalName

user1@contoso.com

user2@contoso.com

user3@contoso.com

user4@contoso.com

user5@contoso.com

user6@contoso.com

user7@contoso.com

user8@contoso.com

user9@contoso.com

user10@contoso.com

Step 2. Run the PowerShell script

The second step is to run the below PowerShell script.

Note: change the path and name of your csv file. 
Connect-MsolService
  
$users = Import-Csv C:\Users\csv \enablemfa.csv
  
foreach ($user in $users)
  
{
 
    $st = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
 
    $st.RelyingParty = "*"
 
    $st.State = "Enabled"
 
    $sta = @($st)
 
    Set-MsolUser -UserPrincipalName $user.UserPrincipalName -StrongAuthenticationRequirements $sta
 
}
  
Write-Host "DONE RUNNING SCRIPT"
  
Read-Host -Prompt "Press Enter to exit"

*** ***