Home > Office365 > Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 02

Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 02


office365_thumb

In my previous Article – Manage Users – Part 01 I have posted information about adding Get-MsolUser, Create New-MsolUsers and Assign Customized License Plan for already created users and for new users.

In this article I will show you how to Provision bulk user accounts using a .CSV file.

What is a .CSV file?

The CSV file type is primarily associated with ‘Comma-Separated Variables’. A comma delimited file is a database exported into a format where each record is a single line and each field in the record is indicated by a comma. It is an easy way to transfer a large amount of data between programs.

In the web based portal there is a particular place where you can upload the CSV file to create user accounts in bulk. But i will show you how to provision bulk users using PS commands with a previously created .CSV file.

 

bULK

 

Below herewith are some information points which would help you to create the accurate .CSV file to perform bulk user add.

  1. The minimum number of rows is two, including the first row of user data column labels.
  2. The maximum number of rows is 251, including the first row of user data column labels.
  3. Only the user name and display name are required entries.
  4. You have to create multiple .CSV file if you want to import more than 250 users.
  5. If you are importing users from different countries or regions, Microsoft recommend creating a separate CSV file for each country or region and performing a bulk import operation for each CSV file. This is because you will be indicating the location of the users in the CSV file as part of this import process, and only one location can be selected per bulk import operation.
  6. Make sure that the User Name column of your CSV file contains the full email address.

 

The following table shows the user data column labels and maximum character length for each in the sample CSV file.

 

User data column label Maximum character length
User Name / UserPrincipalName (Required) The maximum total length of the user name is 79 characters (including @ symbol), in the format name@domain.<extension>. The user’s alias cannot exceed 30 characters and the domain name cannot exceed 48 characters
First Name 64
Last Name 64
Display Name (Required) 256
Job Title 64
Department 64
Office Number 128
Office Phone 64
Mobile Phone 64
Fax 64
Address 128
State or Province 128
ZIP or Postal Code 40
Country or Region 128

 

Sample CSV file is given below,

 

image

 

Below PS cmdlets will allow you to provision new user accounts by using the .CSV file,

 

Import-Csv -Path c:\users.csv | ForEach-Object {New-MsolUser -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -DisplayName "$($_.FirstName) $($_.LastName)" -LicenseAssignment ‘msdivision:ENTERPRISEPACK’ -UsageLocation US } | Export-Csv -Path c:\NewUsers.csv –NoTypeInformation

 

image

 

The purpose of using Export-csv file is to store the account information along with the random password generated for each user. Once the user accounts are created you can distribute password using the generated report. Below screenshot show you the generated temp password for each user.

 

image

 

It is not that much harder isn’t it guys? So try to keep doing Admin tasks using PS commands, this will make your life so easier… Hope this article would help you guys. You can access the previous article using below link, Smile

 

Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 01

Advertisements
Categories: Office365
  1. January 19, 2013 at 2:19 pm

    You are so funny!!! I’ve become obsessed with your website and I spend most of my work hours reading all your archives. And I signed up JUST to post comments. I wish I had found you sooner, and I wish you updated as much as you used to! You must be always busy now though because you are so famous!!

  2. January 25, 2013 at 7:54 am

    Ohh appreciate your comment….

  3. DHill
    August 21, 2013 at 3:48 am

    Thank you for the cool info. I have a question about the old bulk user upload a csv file method compared to the new Office 365. In the old live @ edu method the csv had defined columns for setting a password and a column for using a password switch forcing a change of that password at first login. The Office 365 notes that this option is not available anymore when uploading a csv file with a bulk user add. Do you know of a way to get around that and define a pass with a switch that forces changing the defined pass at first login? As it stands you can of course get a temp pass but who wants the overhead of getting that out there to 4 thousand users every time I upload. Yes, there are ways to sync the AD or Direct Sync but there are other factors to consider with those complexities and our 3rd party print management system. (another story) Any ideas? There are many educational organizations now in the same boat…ugh. Any help would be appreciated. Thanks very much for your time.

  4. August 21, 2013 at 12:52 pm

    To meet your requirement, you can reset the password after the users are imported. For detailed information, please refer to this step by step guide:

    1. Import the users with regular bulk import process as you mentioned above.

    2. Bulk reset the passwords using PowerShell.

    1) Create a CSV file with the columns “UPN” and “NewPassword”
    2) Install the Office 365 cmdlets.
    3) Connect PowerShell to Office 365.
    Connect-MsolService
    4) Run this command to bulk reset password.

    Import-Csv C:\Users\xxx\Desktop\password.csv|%{Set-MsolUserPassword –userPrincipalName $_.upn -NewPassword $_.newpassword -ForceChangePassword $false}

    By using the above method you could generate a common password and ask user to change it.

  5. DHill
    August 21, 2013 at 10:26 pm

    I can work with that. I’ll give it a try and thank you for the nice path to resolution. I have a deadline coming up soon and will set it up as you’ve designed. Cheers, Have a great week!

  1. August 16, 2012 at 7:05 pm
  2. September 9, 2012 at 1:20 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: