Script to add O365 E3 Licenses

msidnam
msidnam used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
carlos sotoIT Administrator
Commented:
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

Author

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.
IT Manager
Top Expert 2010
Commented:

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial