13 January 2017

Assign License via PowerShell | Office 365 | Script

Thanks to my colleague Gareth Harris for this script.

I have recently been running a few large-scale (1000+ mailboxes) and I've had to rely on scripts for assigning licenses and converting mailboxes to shared mailboxes etc.

This blog will cover the script to assign a specific Office 365 license to multiple users, based on their UPN.
  1. Create a folder on your machine called "Office 365"
  2. Create a CSV file with the header of "UserPrincipalName" and then fill the column up with the UPNs of the mailboxes/accounts that you wish to convert to Shared Mailboxes.  Save this as license.csv
  3. Open Notepad and add the following contents:
    $AccountSkuId = "<tenantname>:STANDARDWOFFPACK_IW_faculty"
    $UsageLocation = "AU"
    $Users = Import-Csv "C:\Folder\SubFolder\Office 365\License.csv"
    $Users | ForEach-Object {
    Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation
    Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId
  4. Save this file as "AssignOfficeLicense.ps1"
To find out the AccountSkuId, you can use the following Cmdlet:


Simply copy the entire line of the license you want, and paste that here:

Log into Office 365 through PowerShell.  You can follow this blog post to be able to do that.  You will also need to use the final cmdlet in that post to connect to MSOL.

Navigate to the Office 365 folder and then run the .ps1 file with the following command:


That will then go ahead and start assigning all the Office licenses to the mailboxes that you have mentioned in the CSV file. 

Thanks to my colleague Gareth Harris for this script.

1 comment: