Avatar of msidnam
msidnamFlag for United States of America

asked on 

Script to add O365 E3 Licenses

I was wondering if their was an easy way to add the E3 licenses to our users, possibly through a script? We have 400 licenses that we need to add to specific users. I have a spread sheet with the user names, email addresses, etc.
PowershellMicrosoft 365

Avatar of undefined
Last Comment
msidnam
SOLUTION
Avatar of carlos soto
carlos soto
Flag of Sweden image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of msidnam
msidnam
Flag of United States of America image

ASKER

I think i have everything setup correctly. I used this for part of the code:

Get-MsolUser –UserPrincipalName  $upn | Set-MsolUser –UsageLocation US | Set-MsolUserLicense –AddLicenses "Kaufmanrossin:ENTERPRISEPACK"

Open in new window


I dont get any errors but i dont see it adding the license.
ASKER CERTIFIED SOLUTION
Avatar of Jackie Man
Jackie Man
Flag of Hong Kong image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of msidnam
msidnam
Flag of United States of America image

ASKER

Thank you to the both of you. I needed to use ADv2 even though Adv1 didnt give me any errors. I used a combo of both your codes and ended up with the following:

$file = import-csv O365Users.csv

foreach ($user in $file){

$upn = $user.UserPrincipalName

$user2 = Get-AzureADUser -SearchString $upn

Set-AzureADUser -ObjectId $user2.ObjectId -UsageLocation US

$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
 
$License.SkuId = "6fd2c87f-b296-42f0-b197-1e91e994b900"
 
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
 
$LicensesToAssign.AddLicenses = $License
 
Set-AzureADUserLicense -ObjectId $user2.ObjectId -AssignedLicenses $LicensesToAssign

}

Open in new window

Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo