Back to script samples page
Assigning licenses to multiple users.

This script will perform the following actions:

1. Show you the list of available licenses, their SKU codes, and the quantity remaining for assignment.
2. Display a list of unlicensed users for validation before making licensing changes.
3. Retrieve a list of all unlicensed users located in the United States (based on user property information), and assigns to the 'US' usage location for Office 365.
4. Will assign the EnterprisePack license to all unlicensed users, with a usage location of 'US', in the Contoso domain. You must replace the Contoso domain for your domain name. Replace EnterprisePack for the license type of your choice.

#Assigning licenses to multiple users.

#This first command will import the Azure Active Directory module into your PowerShell session.
Import-Module MSOnline

#Capture administrative credential for future connections.
$credential = get-credential

#Establishes Online Services connection to Azure Active Directory.  
Connect-MsolService -Credential $credential

#This command will show you the list of available licenses, their SKU codes, and the quantity remaining for assignment.
Get-MsolAccountSku

#Display a list of unlicensed users for validation before making licensing changes. 
Get-MsolUser -All -UnlicensedUsersOnly | where {$_.Country -eq 'United States'}

#This command gets a list of all unlicensed users located in the United States (based on user property information), and assigns to the 'US' usage location for Office 365.
Get-MsolUser -All -UnlicensedUsersOnly | where {$_.Country -eq 'United States'} | Set-MsolUser -UsageLocation US

#This command will assign the EnterprisePack license to all unlicensed users, with a usage location of 'US', in the Contoso domain. You must replace the Contoso domain for your domain name. Replace EnterprisePack for the license type of your choice.
Get-MsolUser -All -UnlicensedUsersOnly -UsageLocation 'US' | Set-MsolUserLicense -AddLicenses "contoso:ENTERPRISEPACK"
Downloaded 0 times
* * * * * (1)
Comments