How to assign and remove user Office365 licenses using the AzureADPreview Powershell Module

A couple of months ago the AzureADPreview module was released. The first cmdlet that I experimented with was Set-AzureADUserLicense. And I couldn’t get it to work. There were no working examples showing how to use it, so I gave up and used the Azure AD Graph API directly instead.

Since then the AzureADPreview has gone through a number of revisions and I’ve been messing around with it a little more with each update. The Set-AzureADUserLicense cmdlet has been my litmus test to its functionality. Now that I have both removing and assigning Office 365 licenses working using the Set-AzureADUserLicense cmdlet I’ll save others the pain of working it out and give a couple of working examples.


If like me you have been experimenting with the AzureADPreview module you’ll need to force the install of the newest one. And for whatever reason I was getting an error informing me that it wasn’t signed. As I’m messing around in my development environment sandpit I was confident enough to skip the publisher check. I expect the module to be signed when it is no longer in ‘Preview’.

Install-Module -Name AzureADPreview -MinimumVersion -Force -SkipPublisherCheck
Import-Module AzureADPreview -RequiredVersion

Removing an Office 365 License from a User

Removing an Office365  license with Set-AzureADUserLicense looks something like this.

What if there are multiple licenses? It’s a very similar concept by just looping through each one to remove and add them to the remove collection.

Assigning an Office 365 License to a User

Now that we have the removal of licenses sorted, how about adding licenses?

Assigning a license with Set-AzureADUserLicense looks something like this;

Set-AzureADUserLicense Summary

Moving forward the release version of this AzureAD Preview PowerShell Module will replace the older MSOL Module as I wrote about here. If you’re writing new scripts it’s a good time to start using the new modules.

Follow Darren on Twitter @darrenjrobinson