Office 365 Set-MsolUserLicense: Unable to assign this license because the license options are invalid error

I created a script to automatically add E3 licenses for new users and disable the options we don't want then to have.  I've tested with a test account and it worked just fine.  However, when attempting to run with new accounts, I keep getting the dreaded "Set-MsolUserLicense: Unable to assign this license because the license options are invalid" error.  Frustrated, I manually added the licenses to the users in Admin Center.  

But then I ran the script again and this time it ran with no errors.  So...you can't assign licenses via PowerShell unless you first manually assign them in Admin Center?  That doesn't make sense nor explains why the script ran just fine with the test account previously.  Below is my script:

$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition

$E3 = "Contoso:ENTERPRISEPACK"

$Basic = New-MsolLicenseOptions -AccountSkuId $E3 -DisabledPlans KAIZALA_O365_P3,WHITEBOARD_PLAN2,MYANALYTICS_P2,BPOS_S_TODO_2,FORMS_PLAN_E3, `

STREAM_O365_E3,Deskless,FLOW_O365_P2,POWERAPPS_O365_P2,TEAMS1,PROJECTWORKMANAGEMENT,SWAY,INTUNE_O365,YAMMER_ENTERPRISE, `

MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE,EXCHANGE_S_ENTERPRISE

         

$MyUsers = import-csv -path "$ScriptPath\Migration.csv"

foreach($user in $MyUsers)

    {

        Set-MsolUser -UserPrincipalName $user.Userprincipalname -UsageLocation US

        Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -LicenseOptions $Basic

    }

Hi Canis,

From the description, I understand that you have created a script to assign license to new Office 365 users. However, the script doesn’t work as expected. You may refer to the article to check whether the script can help you. See Bulk license assignment to Office 365 users based on CSV

You can also run this command below to assign a license to many unlicensed users.

Get-MsolUser -All -UnlicensedUsersOnly [<FilterableAttributes>] | Set-MsolUserLicense -AddLicenses "<AccountSkuId>"

For detailed information you refer to the link: Assign licenses to user accounts with Office 365 PowerShell

Moreover, regarding the PowerShell script issue we have dedicated support team therefore I would like to involve our script support team in finding the solution for you, please post your question in the Script Center Forum and there experts’ will focus on the issue to get it resolved more efficiently. 

Regarding this point, we would truly appreciate your kind understanding. 

Best regards,
Shyamal
---------------------
* Beware of scammers posting fake support numbers here.

* We are happy and always here to help you, and share the Microsoft 365 for business online information with you.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks, Shyamal, but this doesn't help.  The command you posted gets ALL unlicensed users and that's that not what I need.  It also assigns ALL services plans and that's not what I need either.  Same thing for the the script in the link; it assigns all services plans. 

 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Canis,

Thanks for the reply. I’m sorry that command/script above doesn’t meet your requirement. 

However, I notice that you have posted question in our dedicated Script Center Forum. Since our Office 365 forum doesn’t focus on PowerShell script issue therefore I would suggest you please keep continue there for further assistance.

We greatly appreciate your kind understanding.

Best regards,
Shyamal
---------------------
* Beware of scammers posting fake support numbers here.

* We are happy and always here to help you, and share the Microsoft 365 for business online information with you.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated September 22, 2023 Views 1,949 Applies to: