dcsimg
Read more on "Server Software Spotlight" »

Managing and Monitoring Office 365 Licenses Assigned to Office 365 Users

By Nirmal Sharma (Send Email)
Posted June 12, 2016


The Get-MsolUser PowerShell cmdlet plays an important role when managing Office 365 Windows Azure Active Directory. Get-MsolUser can be very handy in daily operational tasks related to Office 365 WAAD.

One of the tasks that Office 365 systems administrators are responsible for is monitoring and managing Office 365 licenses and services that are assigned to each Office 365 user. Windows Server Tutorials

The information about Office 365 licenses assigned to Office 365 users will help organizations plan for IT budgets, remove licenses from users that are no longer using Office 365, and control the assignment of Office 365 licenses and services.

Today we'll highlight some valuable Office 365 PowerShell commands and scripts that can help you easily obtain the license information for all Office 365 users.

Assuming that you have installed Microsoft Online Sign-In Assistant for IT Professional and Windows Azure Active Directory Module for Windows, proceed with execution of PowerShell commands/scripts explained throughout this article.

Getting Licensed Office 365 Users

A user must be assigned an Office 365 license before he or she can use Office 365 services. The license can be assigned during the user creation process or at a later point of time.

To get the list of users that are assigned an Office 365 license and store the output in a CSV file, you can run the command below:

Get-MSOluser -ALL | Select-Object UserPrincipalName, DisplayName, IsLicensed | Export-CSV AllLicensedUsers.CSV -NoTypeInformation

Get-MSOlUser identifies the "IsLicensed" attribute for every user that is set to "True" if an Office 365 user is assigned an Office 365 license. The above command retrieves the User Principal Name, Display Name and value assigned to the "IsLicensed" property for each user.

In cases where you need to view the list of Office licenses and services assigned to a particular user, you can use the following PowerShell cmdlet:

$GetUserLicenses = Get-MsolUser -UserPrincipalName "Rick@ExampleIT.OnMicrosoft.com" | Select-Object userPrincipalName -ExpandProperty Licenses
$GetUserLicenses.ServiceStatus

And if you wish to retrieve the licensing information for all Office 365 users, replace the "-UserPrincipalName" parameter with the "-ALL" parameter as shown in the command below:

$GetUserLicenses = Get-MsolUser -All "Rick@ExampleIT.OnMicrosoft.com" | Select-Object userPrincipalName -ExpandProperty Licenses
$GetUserLicenses.ServiceStatus

The above commands display the output in the PowerShell window, but this output might not be as useful as you need.

Instead, you can create a script that you can use to store the information in a CSV file and then run the script daily to ensure you stay on top of the Office 365 licenses assigned to users and remove licenses as needed.

Getting Licenses Count for All Users

Your first task is to get the list of users in Office 365 Tenant, a count of Office 365 Plans that you have bought, the total Office 365 licenses available and then the count of licenses assigned to Office 365 users.

If there is a need to generate such a report, you can use the following PowerShell script.

    $LicenseReport = "C:\Temp\LicenseReport.CSV"
    IF (test-Path $LicenseReport)
    {
Remove-item $LicenseReport } $AllUsers = (Get-MSOluser -ALL).Count $TotalLicenseUsers = (Get-msoluser -ALL | Select-Object UserPrincipalName -ExpandProperty licenses).Count $PlanCount = (Get-MsolAccountSku).Count $TotalLicenses = Get-MsolAccountSku | Measure-Object ActiveUnits -Sum $STR = "Total Users: "+$AllUsers Add-Content $LicenseReport $STR $STR = "Total Office 365 Plans: "+$PlanCount Add-Content $LicenseReport $STR $STR = "Total Office 365 Licenses in Plan: "+$TotalLicenses.Sum Add-Content $LicenseReport $STR $STR = "Total Licenses Assigned: "+$TotalLicenseUsers Add-Content $LicenseReport $STR

The above PoweShell script generates a report named LicenseReport.CSV in the C:\Temp folder. The PowerShell script removes the report file and generates a new one every time you run the PowerShell script.

A sample report generated by using the script above looks like this:

Office 365 PowerShell Report #1

Getting Licenses Assigned to each Office 365 User

The above script provides the licenses count for all Office 365 Users. You might instead need a report that contains the Office 365 user name and Office 365 Plan and licenses and services assigned to each user.

In this case, you can use the PowerShell script below:

    $UserLicFile="C:\Temp\UserLicensesPerUser.CSV"
    IF (test-Path $UserLicFile)
    {
    Remove-Item $UserLicFile
    }
    $STR = "User Principal Name, Office 365 Plan, Office 365 Service,Service Status"
    Add-Content $UserLicFile $STR
    $GetAllUsers=Get-MsolUser -All | Select-Object UserPrincipalName -ExpandProperty Licenses
    ForEach ($AllU in $GetAllUsers)
    {
    $SelUserUPN = $AllU.UserPrincipalName
    $T = $AllU
    $i = 0
    ForEach ($AllITems in $T)
    {
    $T.Count
    $T[$i].AccountSkuId
    $Account = $T[$i].AccountSkuId
    $TTT = $T[$i].ServiceStatus
    ForEach ($AllR in $TTT)
    {
    $GR = $AllR.ServicePlan.ServiceType
    $GZ = $AllR.ProvisioningStatus
    $STRNow = $SelUserUPN + "," + $Account + "," + $GR + "," + $GZ
    Add-Content $UserLicFile $STRNow
    }
    $i = $i + 1
    }
    }

When you run the above PowerShell script, it generates a report file in CSV format that contains the license information about all of your Office 365 users.

As you can see in the sample report below generated by this PowerShell script, it displays the Office 365 user principal name to which the office 365 license is assigned, the Office 365 plan from which the license is assigned, Office 365 Services that are assigned, and the status of individual services.

Office 365 PowerShell Report #2

It is recommended that you run both the scripts provided in this article to help you get a clarity on the Office 365 licenses.


Nirmal Sharma is a MCSEx3, MCITP and Microsoft MVP in Directory Services. He specializes in directory services, Microsoft Azure, Failover clusters, Hyper-V, System Center and Exchange Servers, and has been involved with Microsoft technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to Health Packs for ADHealthProf.ITDynamicPacks.Net solutions. Nirmal can be reached at nirmal_sharma@mvps.org.

Follow ServerWatch on Twitter and on Facebook

Page 1 of 1

Read more on "Server Software Spotlight" »

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date