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

PowerShell MCP Azure Function Server

Recently under the experimental Azure Functions build Microsoft Developer Advocates have shown enabling Azure Functions…

2 weeks ago

EntraPulse – Your AI-Powered Gateway to Microsoft Graph & Docs

Today, I’m super excited to finally announce the Beta release of EntraPulse Lite – a…

2 months ago

Lokka MCP Authentication Enhancements

I'm excited to share some significant authentication enhancements I've contributed to the Lokka MCP Server…

3 months ago

AI Inception: Building AI Solutions with AI for AI

Last month I had the pleasure of speaking at the Sydney event for Global Azure.…

4 months ago

A Have I Been Pwned MCP Server for Claude

Model Context Protocol (MCP) is a powerful framework that extends AI clients like Claude and…

6 months ago

Azure AI Developer Hackathon

I've just completed participating in the Azure AI Developer Hackathon that was looking to provide…

6 months ago

This website uses cookies.