How to assign License to unlicensed users automatically


This script will assign License to unlicensed user automatically.


This script will auto assign License to unlicensed users if there's only one type of SKU in an organization. If an organization has multi-type SKUs, an excel sheet will be popped out for edition after you run the script. Then the script will assign license based on the excel file.


You can use this script in the following way.

1. Open Windows PowerShell.

2. Type the one command< Script Path> at the Windows PowerShell Console.

For example, type C:\Script\ UnlicensedUser.csv

Here are some code snippets for your reference.

$UsersCSV = Import-Csv $ExportPath
Foreach($User in $UsersCSV)
    Set-MsolUserLicense -UserPrincipalName $User.UserPrincipalName -AddLicenses $User.LicenseType


 Example 1: Assign license to the unlicensed users. This organization has different types of license.

The sample is shown below

Command Screenshot

 Result Screenshot:




Exchange Online
Windows PowerShell 2.0

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.