Identity and Access Management

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 2.0.0.7 -Force -SkipPublisherCheck
Import-Module AzureADPreview -RequiredVersion 2.0.0.7

Removing an Office 365 License from a User

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

See the gist on github.

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.

See the gist on github.

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;

See the gist on github.

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

Darren Robinson

Bespoke learnings from a Microsoft Identity and Access Management Architect using lots of Microsoft Identity Manager, Azure Active Directory, PowerShell, SailPoint IdentityNow and Lithnet products and services.

View Comments

Recent Posts

Visualising your IP Address using PowerShell and AI

A few weeks back the Microsoft AI Tour was in Sydney Australia. There was a…

3 weeks ago

Where the heck is the PowerShell Module loading from?

If you're anything like me you always have PowerShell open, and often both PowerShell and…

4 months ago

Express Verified ID Setup

Decentralised Identity is a technology I'm passionate about and have written many posts and tools…

5 months ago

Orchestrating 1Password with PowerShell

Over two years ago I authored a PowerShell Module that enabled the automation of 1Password.…

8 months ago

Entra ID Tenant ID & Custom Domains PowerShell Module

Buried in my PowerShell Snippets Vol 4 post from 2021 is the PowerShell script and…

8 months ago

Windows Subsystem for Linux instance has terminated

Short post on how to recovery from "The Windows Subsystem for Linux instance has terminated"…

9 months ago

This website uses cookies.