Link to home
Start Free TrialLog in
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.
SOLUTION
Avatar of carlos soto
carlos soto
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msidnam

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msidnam

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