How to get a list of all Licensed Office 365 users with PowerShell

Install required software

1.     Ensure you are running Windows 8.1, Windows 8, or Windows 7.

2.     Make sure you have the .NET Framework 3.51 feature.

3.       Make sure you have the latest updates.

4.     Install the Microsoft Online Services Sign-In assistant.

5.       Install the Windows Azure Active Directory (Azure AD) module for the appropriate version of your operating system.

6.       Open powershell as administrator.

7.       Import-Module MSOnline

8.       Get-Credential (Windows PowerShell  dialog box appears)

9.       Enter your credentials.

10.   Connect-MsolService

11.   Get-MsolUser -All |Sort isLicensed

12.   Finish.

Via – Getting Started with Office 365 and PowerShell – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs.