Link to home
Start Free TrialLog in
Avatar of Jody Davis
Jody DavisFlag for United States of America

asked on

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

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!
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

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

Avatar of Jody Davis

ASKER

thank you. i'll try this out today.
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?
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

** 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.
ASKER CERTIFIED SOLUTION
Avatar of FOX
FOX
Flag of United States of America 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
thanks man, that was great!
Nice
$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