PowerShell Script To Move List Of Users To Office 365 And Assign Them O365 Licenses

Office 365

Office 365 is a SaaS platform which is being used by many organizations these days, and it can become quite hard for IT administrators to onboard their users to Office 365 manually. Of course, this may not be the case when your user identities get synced to Azure AD from on-premises AD using AAD connect tool.

However, if you’re one of the organizations which has totally buried all your IT infrastructure implementation and decided to go with a Cloud implementation completely, then it's possible that you as an IT administrator should take care of on-boarding your users to Azure AD. As we all know, this is indeed quite a time consuming task if we have to do it manually and then assign the appropriate licenses to all the users. So, to bypass all those manual efforts, I’ve put together this PowerShell script which will do the magic for you.
 
Alright, let’s get into details ….

  1. Sign-in to your Office 365 Admin Center using your global admin account and navigate to the Active users section, as shown in the image below.

    Office 365

  1. At this moment, you might see only the user account that was used to set up the Office 365 tenant.

    Note
    In my case, you might see three users as I manually created them using the Add a user “ option.
  1. Create a CSV file which has the details of all your users by following the guidelines mentioned in this article. The below mentioned screenshot depicts the CSV file which I’ve prepared which has the list of all my users.

    Office 365

  1. Once done, please log in to the PowerShell window and type the below mentioned command as shown in the image below. This will tell you the type of license that your tenant is using and how many licenses have been utilized so far.

    Office 365

    Note
    In my case, you may notice that my tenant is on Office 365 E5 Enterprise E5 plan +EMS (Enterprise Mobility ) and it also displays how many licenses have been consumed so far.
  1. Prior to running the above command, please ensure that you’re connected to your Office 365 tenant via PowerShell, if not please follow the below article to do that first.

    https://technet.microsoft.com/library/dn975125.aspx
  1. Now, let’s specify the required variables for the PowerShell script.

    $UsersToAdd = Import-Csv C:\Users\Vignesh\Documents\Import_User_Sample_en.csv

    $LicenseToAdd = "sptech80:ENTERPRISEPREMIUM" - This information was grabbed from the Get-MsolAccountSKU command which we ran in the above step.

    1. $UsageLocation = "US"  
    2. $LicenseOptions = New-MsolLicenseOptions -AccountSkuId $LicenseToAdd  

    Office 365

  2. Once you’re done specifying the required variables, please go ahead and run the below mentioned PowerShell command as shown in the image.

    1. $UsersToAdd | ForEach - Object   
    2. {  
    3.     New - MsolUser– UserPrincipalName $_.UserPrincipalName - DisplayName $_.DisplayName  
    4.     Set - MsolUser - UserPrincipalName $_.UserPrincipalName - UsageLocation $UsageLocation  
    5.     Set - MsolUserLicense - UserPrincipalName $_.UserPrincipalName - AddLicenses $LicenseToAdd - LicenseOptions $LicenseOptions  
    6. }  

    Office 365

  3. You may notice that your users are getting created after running the script as shown in the image above and the licensing tab might display the status as “False”. That’s due to the time taken for the script to reflect the licensing details as it first creates the user and then assign the license to the user’s account. This is quite normal and hence you don’t need to panic about the “isLicensed” column
  1. You can verify the status of the users as well as the licenses assigned to them by running the “Get-MsolUser” command. This time it should display the licensing details correctly.

    Office 365

  2. Additionally, you can also navigate to the “Active users” section to verify the same.

    Office 365

Thanks for reading this post ….Good luck with Office 365 !!!

Up Next
    Ebook Download
    View all
    Learn
    View all