We help IT Professionals succeed at work.

Need Powershell command to bulk assign E3 licenses to newly-created O365 mailboxes

112 Views
1 Endorsement
Last Modified: 2018-12-19
I have a .csv file of users i need to assign O365 E3 licenses. I need a powershell command to bulk assign the licenses using the .csv. I have a hybrid Exchange Server 2013 onprem server and our mailboxes are in O365 in the cloud.  Thanks!
Comment
Watch Question

Jose Gabriel Ortega CastroTop-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
It's not that simple.

1. Connecto to MsolService
   a. Open a powershell console as administrator
   b. Run

install-module msonline

Open in new window


  c. run and add the credentials:
Connect-MsolService

Open in new window


2. Find all users that doens't have licences assigned:
  a. Run:
   Get-MsolUser -All -UnlicensedUsersOnly

Open in new window


3. you can only assign license to those users that DOES have a location:
 a. You can find all the users that doens't have assigned a location:
 
Get-MsolUser -All | where {$_.UsageLocation -eq $null}

Open in new window

b. Set location like this:
Set-MsolUser -UserPrincipalName "<Account>" -UsageLocation <CountryCode>
ex: et-MsolUser -UserPrincipalName "belindan@litwareinc.com" -UsageLocation US

Open in new window

 
If you use the command without the -All you'll get the 1st 500.
4. Find MsolAccountSku
a. run
Get-MsolAccountSku

Open in new window


Find the SKU of your ENTERPRISEPACK.
5. Assign Licenses:
a. Single user
Set-MsolUserLicense -UserPrincipalName "<Account>" -AddLicenses "<AccountSkuId>"

Open in new window

Office 365 Enterprise E3 (<domain>:ENTERPRISEPACK)
b. Massive Asignement:
$x = Get-MsolUser -All -UnlicensedUsersOnly [<FilterableAttributes>]; $x | foreach {Set-MsolUserLicense -AddLicenses "<AccountSkuId>"}

Open in new window



-------------------

$CSVPath="C:\here.csv"
Install-Module msonline
Connect-Msolservice
#Read csv
$objs = Import-Csv -Path "$CSVPath"
$SKUID= Get-MsolAccountSku | where { $_.Accountskuid -like "*ENTERPRISEPACK"} | select -ExpandProperty AccountSkuid
$objs | foreach {Set-MsolUserLicense -AddLicenses  $SKUID}

Open in new window

Jody DavisSystems Engineer

Author

Commented:
thank you. i'll try this out today.
Jody DavisSystems Engineer

Author

Commented:
Am I correct in saying I need to:
1. ensure that all users I want to run the script on have their location set
2. have a .csv with one column that has jsmith@constoso.com, jdoe@contoso.com, etc of the accounts I want to license
3. input the result of the ENTERPRISEPACK query into your script
4. run the script

That will do it, and this will license only those users in the .csv. Is that all correct?
Jose Gabriel Ortega CastroTop-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
Yes, last correction would be that I would need to know the column name for that UPN (joe@contoso.com), assuming that is "Column name" the final line would be

$objs | foreach {Set-MsolUserLicense $_."Column name" -AddLicenses  $SKUID}

Open in new window

Jody DavisSystems Engineer

Author

Commented:
** last request - how can i first bulk assign the location only to people in that .csv? (don't want to do it to all objects)

you've been great.
Active Directory/Exchange Engineer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Jody DavisSystems Engineer

Author

Commented:
thanks man, that was great!
FOXActive Directory/Exchange Engineer
CERTIFIED EXPERT
Top Expert 2015

Commented:
Nice
Jose Gabriel Ortega CastroTop-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
$CSVPath="C:\here.csv"
#Install-Module msonline copmmented becasue i assume that is already installed
Connect-Msolservice
#GET SKUID
$SKUID= Get-MsolAccountSku | where { $_.Accountskuid -like "*ENTERPRISEPACK"} | select -ExpandProperty AccountSkuid

#read and set location
Import-Csv -Path "$CSVPath" | Set-MsolUser $_.UserPrincipalName -UserPrincipalName -UsageLocation US
#read and set SKUID license
Import-Csv -Path "$CSVPath" | Set-MsolUserLicense -identity $_.UserPrincipalName  -AddLicenses  $SKUID

Open in new window

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions