Post date: Sep 02, 2015 10:33:56 AM
To get started, open a SharePoint Online Management Shell, and connect to Office 365 via the cmdlet Connect-MsolService. When prompted, enter the corresponding administrator credentials.
To get a list of all users within your tenant (both those with licenses assigned to them and those without), you can now use the cmdlet Get-MsolUser. Execute Get-MsolUser | Get-Member | Out-GridView to get a nicely formatted list of all available properties for the user objects returned by Get-MsolUser.
Of particular interest is the property isLicensed, which indicates whether a user has a license assigned (TRUE) or not (FALSE). It is now possible to filter the users returned by Get-MsolUser and only see those that are licensed by running the command Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" }
Note: By using "FALSE" instead of "TRUE", you can get a list of all users that do currently not have any license assigned to them.
The list of licsensed user can now be processed further, for example by exporting it to a CSV file that can be opened in Excel for reporting purposes or further analysis: Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" } | Export-Csv c:\LicensedUsers.csv
Note that this exports all available properties for the licensed users. To export only specific properties, you can use the Select-Object cmdlet to specify which properties to use. As an example, only UserPrincipalName, DisplayName, Country, and Department will be exported:
Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" } | Select-Object UserPrincipalName, DisplayName, Country, Department | Export-Csv c:\LicensedUsers.csv