Automating the importing of multiple users

Scenario description

To save time on importing multiple users into Office 365, automate with 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 user@contoso.com; however you can provide data for any writable user profile field (eg. names, contact numbers, addresses, etc).

A User Principal Name (UPN) is the name of a system user in an e-mail address format. The user name (or "username") is followed by the "at sign" followed by the name of the Internet domain with which the user is associated.

Two sample CSV files have been prepared for this scenario to provide example syntax.

Automating the importing of multiple users

Importing Users (Basic)

To begin, you will need to connect to Azure Active Directory.

Import-Module MSOnline $credential = get-credential Connect-MsolService -Credential $credential

Prepare a CSV file with the following two column headers; UserPrincipalName, DisplayName, and add a new user on each row of the CSV. Note that as we are not stipulating a password, one will be generated automatically by Office 365. Note: A User Principal Name (UPN) is the name of a user in an e-mail address format. The user name (or "username") is followed by the "at sign" followed by the name of the Internet domain with which the user is associated.

Import-Csv .\Import_new_user_Basic.csv | ForEach-Object { New-MsolUser -UserPrincipalName      $_.UserPrincipalName -DisplayName $_.Display }

Importing Users (Detailed)

To begin, you will need to connect to Azure Active Directory.

Import-Module MSOnline $credential = get-credential Connect-MsolService -Credential $credential

Prepare a CSV file with the following column headers, and populate as many user rows as required. UserPrincipalName,DisplayName,FirstName,LastName,Title,Password,UsageLocation,Office,Department,MobilePhone,StreetAddress,City,State,PostalCode,Country Note that the column headers should have no spaces, as each needs to be referenced by the $_. element of the PowerShell script. Only the UserPrincipalName and DisplayName fields are compulsory, and blank values will simply be skipped.

A User Principal Name (UPN) is the name of a system user in an e-mail address format. The user name (or "username") is followed by the "at sign" followed by the name of the Internet domain with which the user is associated. The UsageLocation code is the location of the user and that the country selected should be from our list of supported countries.

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 }
Resources
Comments

No Comments