Assigning licenses to Exchange Online users with PowerShell

You’ve setup your Office 365 tenant, you’ve configured DirSync, and you’ve done a test migration. Now you’re ready to start migrating your user’s mailboxes to Exchange Online in bulk. The last hurdle before you can do a big batch migration of mailboxes is assigning licenses to user’s accounts in the Office 365 portal. Sure you can click through each user in the portal one-by-one and assign licenses, but I’ve done migrations with tens and even hundreds of thousands of mailboxes and assigning all those licenses one-by-one would make anyone crazy. Good news loyal readers, I’m going to show you how to license those user’s accounts with PowerShell.

Step One is opening a remote PowerShell connection to your Office 365 tenant. I recommend you read THIS post and script that process.

Step Two is figuring out what license SKUs you have available. Get-MsolAccountSku is the PowerShell command to that will list the SKUs you have available on your tenant.

Step Three is putting together three PowerShell commands to complete your task. Get-MsolUser, Set-MsolUser, and Set-MsolUserLicense are the commands you’ll need to string together. To assign the same license to all your unlicensed users the command looks like this

Get-MsolUser –UnlicensedUsersOnly | Set-MsolUser –UsageLocation US  | Set-MsolUserLicense  –AddLicenses  Tenant:AccountSku

If you have several different groups of users that need to have different types of licenses assigned, you’ll need to modify that command a bit. For instance if the Accounting department needs a specific license you can modify the Get-MsolUser section to include –Department “Accounting”.