Back to script samples page
Importing users with detailed user information using a CSV file

The best way to bulk add new users is by using PowerShell.
To import a large number of users, you need to first prepare a CSV file with the relevant user information.
The minimum required field information to create a user is a Display Name, and a User Principal Name (UPN) in the format; however you can provide data for any writable user profile field (eg. names, contact numbers, addresses, etc)

Prepare a .CSV file (named Import_new_user_Detailed.csv for example) with the following comma delimited format: UserPrincipalName, DisplayName, FirstName, LastName, Title, Password, UsageLocation, Office, Department, MobilePhone, StreetAddress, City, State, PostalCode, Country or use the sample file provided in this scenario section.

#Importing users with detailed user information using a CSV file

#This first command will import the Azure Active Directory module into your PowerShell session.
Import-Module MSOnline

#Capture administrative credential for future connections.
$credential = get-credential

#Establishes Online Services connection to Azure Active Directory  
Connect-MsolService -Credential $credential

#This command Imports the users in your prepared CSV file. 
#It assumes the CSV file is located in the same directory as your current powershell session with the following column headers: UserPrincipalName,DisplayName,FirstName,LastName,Title,Password,UsageLocation,Office,Department,     MobilePhone,StreetAddress,City,State,PostalCode,Country. Each new user should be on a new row of the CSV.
#Note that the column headers should have no spaces, as each needs to be referenced by the $_.<ColumnName> element of the PowerShell script. Only the UserPrincipalName and DisplayName fields are compulsory, and blank values will simply be skipped.
Import-Csv .\Import_new_user_Detailed.csv | ForEach-Object { New-MsolUser -UserPrincipalName $_.UserPrincipalName -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName -Title $_.Title -Department $_.Department -Office $_.Office -MobilePhone  $_.MobilePhone -StreetAddress $_.StreetAddress -City $_.City -State $_.State -PostalCode $_.PostalCode -Country $_.Country -Password $_.PassWord }
Downloaded 0 times
* * * - - (2)