Report on Office 365 licensed and non-licensed users

Scenario description

These scripts will allow you to view Office 365 licensing information for multiple users including both licensed and non-licensed users.

In this script we set the maximum number of results to 10,000 users.

We have also included a script to show unlicensed users.

Should you have a large number of users it is best to output this information into a CSV file.  Please review the "Exporting data to a .CSV file" scenario to learn about this helpful command.

We recommend using Excel to open and view .CSV files.

Connect to Azure Active Directory and Report on Office 365 Licensed and Non-licensed Users

To begin, you will need to load the Azure Active Directory module to be able to run the report.
Import-Module MSOnline
$credential = Get-Credential
Connect-MsolService -Credential $credential

To report on licensed users, run the following script. In this example, we have limited the number of results to 10,000 users by setting the "-maxresults 10000" parameter.

Get-MsolUser -maxresults 10000 | Where-Object {$_.isLicensed -eq $true -and $_.Licenses[0].ServiceStatus[3].ProvisioningStatus -ne "Disabled"}
To report on non-licensed users, run the following script. In this example, we have used a limited the number of results to 10,000 users by setting the "-maxresults 10000" parameter.
Get-MsolUser -maxresults 10000 -UnlicensedUsersOnly
To redirect your output to a CSV file append the following command to any reporting command.
<Command> | export-csv <ExportFileName.csv>

For example, to export the results of the non-licensed users into a CSV file, run the following command. You can replace the C:\reports\non-licensed_users.csv with a location and file name of your choosing.

Get-MsolUser -maxresults 10000 –UnlicensedUsersOnly | export-csv C:\reports\non-licensed_users.csv
Resources
Get a list of all users within your tenant

Getting all Licensed Office 365 users with PowerShell

Comments