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.
LVL 2
msidnamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carlos sotoIT AdministratorCommented:
hi

Ive used the following script

$file = import-csv csvFile.csv

foreach ($user in $file){

$upn = $user.UserPrincipalName

set-msoluserlicense -userprincipalname $upn -addlicenses <license type>
}

Open in new window


In the csv file i had a column named "UserPrincipalName", so i just get that information for each user

Too see what the name of the license is, run the following command:
Get-MsolAccountSku

Open in new window


Usually the license is named as <your office 365 tenant>:<type of license>

Heres a good guide from MS for assigning licenses
https://technet.microsoft.com/en-us/library/dn771770.aspx
msidnamAuthor Commented:
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.
Jackie ManIT ManagerCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msidnamAuthor Commented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.