To create multiple users, assign licenses to multiple users, or do both at the same time, we can use data stored in a CSV file, text file, or even a SharePoint list.
In the following example, we will cover bulk user creation using a CSV file.
As mentioned previously, to create a new user the mandatory parameters are userprincipalname
and DisplayName
.
The CSV will need to be in the following format:
FirstName, LastName, Country
Bob, Smith, USA
Sanjay, Shah, UK
To implement this, we will need to connect to the Office 365 service first and import the input file; the next step is to store the info in variables, and the last step is to create the users in Office 365:
$users = Import-CSV "C:\Users.csv" foreach ( $user in $users){ $FirstName = $user.FirstName $LastName = $user.LastName $DisplayName = build it as per company policy $userName = build it as per company policy New-MSOLUser -UserPrincipalName $userName -DisplayName $DisplayName...