Find unlicensed users with powershell in Office 365 and apply a license.

If you have many users synced to Office 365. It will be more efficient to user powershell to license them.

This is how:

connect-msolservice and enter crendentials.

Get-MsolAccountSku will display the license types.
And then:
$AccountSkuId =
“tenantname:STANDARDWOFFPACK_STUDENT”
$UsageLocation =
“FI”
$LicenseOptions =
New-MsolLicenseOptions -AccountSkuId
$AccountSkuId
$Users =
Get-MsolUser -All
| Where-Object
{$_.isLicensed
-like “false”}
$Users |
ForEach-Object {
Set-MsolUser -UserPrincipalName
$_.UserPrincipalName
-UsageLocation $UsageLocation
Set-MsolUserLicense -UserPrincipalName
$_.UserPrincipalName
-AddLicenses $AccountSkuId
-LicenseOptions $LicenseOptions
}



$users part find all Unlicensed users and apply a license to them.


Save it so .ps1 and run!


Enjoy powershell!

Author: Harri Jaakkonen

Leave a Reply

Your email address will not be published. Required fields are marked *