Retrieve All Account License And Service Details In Office 365

In this article, I have included loads of blog examples on how to connect to your Office 365 account and retrieve account details like license name, service plan, licensed users, and external users. You have to follow the below instructions for better results.
  • Connect to AzureAD
  • PowerShell code

Connect to AzureAD

 
Run Windows PowerShell as an administrator.
 
In that command window, run "Install-Module -Name AzureAD" to install the AzureAD, if it is not installed on your end. If it shows a message about installing a module from an untrusted repository, then type "Y" and press the Enter button. 
 
Retrieve All Account License And Service Details In Office 365
 
Then run the command "Connect-AzureAD". It will prompt you to sign in to your Microsoft account. Type your Office 365 account user name and password and click Next.
 
Retrieve All Account License And Service Details In Office 365
 
Then run the command "Install-Module MSOnline" to install MSOnline on your end. If it prompts you to install the NuGet provider, type ‘Y’. If it prompts you  to install the module from PSGallery, type ‘Y’ and press ENTER.
 
Run the "Connect-MsolService" command and then provide your credentials and click on next.
 
Retrieve All Account License And Service Details In Office 365

PowerShell Code

 
The below code retrieves the details of license name, licensed users, external users, and services plan of your Office365 Account.
  1. $credential = Get - Credential  
  2. Connect - MsolService - Credential $credential  
  3. try {  
  4.     #Retrieve license list present inside tenant  
  5.     $license = Get - MsolAccountSku  
  6.     for ($i = 0; $i - lt $license.Count; $i++) {  
  7.         $nameLicense = $licenseLists[$i]  
  8.         #Retrieve License Name  
  9.         Write - Host "License Name ="  
  10.         $nameLicense.SkuPartNumber  
  11.         #Retrieve assigned users count  
  12.         Write - Host "Assigned Users ="  
  13.         $nameLicense.ConsumedUnits  
  14.     }  
  15.     $extUserCount = Get - MsolAccountSku | Where - Object {  
  16.         $_UserPrincipalName - like "*#EXT#*"  
  17.     }  
  18.     Write - Host "External User = "  
  19.     $extUserCount.Count  
  20.     #Show the service status of Tenant  
  21.     Get - MsolAccountSku | Select - ExpandProperty ServiceStatus  
  22.     sleep 10  
  23. catch {}  
The out-put will be like the below image.
 
Retrieve All Account License And Service Details In Office 365