Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Getting “Unable to assign this license because it is invalid” in Office 365 PowerShell with Set-MsolUserLicense when you know darn well it’s valid
December 08
Getting “Unable to assign this license because it is invalid” in Office 365 PowerShell with Set-MsolUserLicense when you know darn well it’s valid

I’ve been working on a blog post about the script I use to license users inside of Office 365. It’s a doozy. You’re going to love it, I promise. As a rule, I have someone proof read all of my blog posts, especially ones that have PowerShell code in it. For those of you that have read any of my blog posts, that might come as a shock, but it’s true. When Shane was testing my code he kept getting errors. In this case, I just chalked it up to his ineptitude, which is the source of many of his troubles, so I blew him off. I had tested the crap out of this PowerShell script so I trust it more than I trust Shane.

But a couple of days ago I was running my trusty script and I got the error. Now stuff was getting serious! Here’s the code I ran:

PS C:\> $lic1 = "MOD873457:ENTERPRISEPREMIUM"
PS C:\> $user = "alonso@MOD873457.onmicrosoft.com"
PS C:\> Set-MsolUserLicense -UserPrincipalName $user -AddLicenses $lic1

Here’s the very unpleasant response that PowerShell gave me:

Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
At line:1 char:1
+ Set-MsolUserLicense -UserPrincipalName $user -AddLicenses $lic1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Set-MsolUserLicense], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.InvalidUserLicenseException,Microsoft.Online.
   Administration.Automation.SetUserLicense

I did like it suggested, and sure enough the SKU was legit:

PS C:\> Get-MsolAccountSku

AccountSkuId                ActiveUnits WarningUnits ConsumedUnits
------------                ----------- ------------ -------------
MOD873457:ENTERPRISEPREMIUM 25          0            1
MOD873457:PROJECTPREMIUM    25          0            0

Here is my failure in pictures

 

SNAGHTML1d5d4728

It turns out that Shane is not an idiot. Well, if he is, this is not an example of it. It’s just a poor error message. While the error says the license is invalid, it’s really not. It threw that error because that user already had that license.

We can verify that with this command:

(Get-MsolUser -UserPrincipalName $user).licenses

The output looks like this:

image

Unfortunately there’s no good way that I know of to tell why you’re getting that error, or walk through a user’s existing licenses and see if it’s already applied. It can be done, but it’s ugly text parsing. If I figure out something elegant, I’ll let you all know.

After much swearing and figuring this out on my own, I did find one vague reference to it in Microsoft’s

Assign licenses to user accounts with Office 365 PowerShell document.

image

Not helpful, Microsoft, not helpful.

 

tk

ShortURL: http://www.toddklindt.com/InvalidO365SKU

Comments

There are no comments for this post.

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 Please Support my Sponsors