<link href="https://fonts.googleapis.com/css?family=Roboto:100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic&amp;display=swap" rel="stylesheet"/>
3 minutes reading time (583 words)

Create multiple Office 365 users from csv using PowerShell

How to create Office 365 user accounts, assign licenses and enable MFA using PowerShell with steps for creating multiple users in bulk by importing from csv file

Connect to Azure Active Directory PowerShell

Connect-MsolService 

Check available licenses SKUs

Run Get-MsolAccountSku to find the Office 365 license sku to use for assigning licenses

Get-MsolAccountSku 

Microsoft 365 SKU Part Numbers and Product Names

Product Name SKU
Microsoft 365 E3 SPE_E3
Microsoft 365 Business Premium SPB
Office 365 Enterprise E3 ENTERPRISEPACK

Create user account and assign a license

Create a new user account using the new-msoluser PowerShell command

New-MsolUser options

-UsageLocation
  • This is the two character country or region code, when you create users you must assign a usage location

  • Usage location is used to determine which Microsoft 365 services are available for the country that the user is in

Country code examples:

AU Australia
DE Germany
FR France
GB United Kingdom
US United States

You can get a complete list of country codes from MaxMind

GeoIP Legacy Codes
https://dev.maxmind.com/geoip/legacy/codes

-License Assignment
  • Used to specify the type of license that will be assigned to the user, use the AccountSkuId from Get-MsolAccountSku
New-MsolUser -DisplayName "Philip Fry" -FirstName Philip -LastName Fry -UserPrincipalName philip@domain.com -UsageLocation GB -LicenseAssignment techlabscloud:ENTERPRISEPACK -Password PASSWORD 

Enable MFA for one user 

We will create a StrongAuthenticationRequirement variable $sta, this will then be used to enable MFA for the user by running the Set-MsolUser -StrongAuthenticationRequirements PowerShell command

# Create a StrongAuthenticationRequirement object
$st = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
$st.RelyingParty = "*"
$st.State = "Enabled"
$sta = @($st)

# Enable MFA for the user 
Set-MsolUser -UserPrincipalName philip@domain.com -StrongAuthenticationRequirements $sta
 

MFA is now enabled

Create multiple user accounts using New-MsolUser and Import-Csv

Create a csv file list of new users using these column headings

UserPrincipalName, FirstName, LastName, DisplayName, UsageLocation, AccountSkuId

Run the MsolUser PowerShell command with Import-Csv to create Office 365 users in bulk from the csv file

Import-Csv -Path C:\Temp\planet-express-users.csv | foreach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuId -Password $_.Password} | Export-Csv -Path C:\temp\created-users.csv
 

User accounts have been created and licenses assigned

Enable MFA for multiple users using Set-MsolUser and Import-Csv

Let's use the same csv list that we used to create the user accounts to enable MFA for all users on the list

$users = Import-Csv -Path C:\Temp\planet-express-users.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
}
 

All user accounts from the csv list now have MFA enabled

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Friday, 31 October 2025
You can help support this website by buying me a coffee!
Buy Me A Coffee