Office 365 Users License Report with Powershell

We can find and list the applied license details of all the office 365 users by using the Azure AD powershell cmdlet Get-MsolUser. The Get-MsolUser cmdlet returns the user’s license details along with other common user information.
 

Note: Before proceed, Install and Configure Azure AD PowerShell

Export Office 365 Users License Detail to CSV

The following powershell script gets the applied license detail for all the office 365 users by using Get-MsolUser cmdlet and it exports the output to csv file by using Export-CSV cmdlet.

$users = Get-MsolUser -All
$users | Foreach-Object{ 
  $licenseDetail = '' 
  $licenses='' 
  if($_.licenses -ne $null) {
ForEach ($license in $_.licenses){
  switch -wildcard ($($license.Accountskuid.tostring())) { 
           '*POWER_BI_STANDALONE' { $licName = 'POWER BI STANDALONE' } 
           '*CRMSTANDARD' { $licName = 'CRM Online' }
           '*O365_BUSINESS_PREMIUM' { $licName = 'Office 365 BUSINESS PREMIUM' } 
           '*ENTERPRISEPACK' { $licName = 'Office 365 (Plan E3)' }  
           default { $licName = $license.Accountskuid.tostring() }
        }         

  if($licenses){  $licenses = ($licenses + ',' + $licName) } else { $licenses = $licName}
ForEach ($row in $($license.servicestatus)) {

if($row.ProvisioningStatus -ne 'Disabled') {          
       switch -wildcard ($($row.ServicePlan.servicename)) { 
           'EXC*' { $thisLicence = 'Exchange Online' }  
           'LYN*' { $thisLicence = 'Skype for Business' } 
           'SHA*' { $thisLicence = 'Sharepoint Online' }       
           default { $thisLicence = $row.ServicePlan.servicename }  
       }         
 if($licenseDetail){ $licenseDetail = ($licenseDetail + ',' + $thisLicence) }  Else { $licenseDetail = $thisLicence}}
}}}
New-Object -TypeName PSObject -Property @{    
    UserName=$_.DisplayName  
    IsLicensed=$_.IsLicensed 
    Licenses=$licenses 
    LicenseDetails=$licenseDetail }
}  | Select UserName,IsLicensed,Licenses,LicenseDetails |
Export-CSV "C:\Office-365-User-License-Report.csv" -NoTypeInformation -Encoding UTF8

Explore the app Microsoft 365 Manager to manage licenses from a user-friendly interface without using Powershell script. You can generate different license reports to track your Microsoft 365 license usage. You can also assign, remove, and update licenses for individual and bulk users.

Office 365 License Reports »

Office 365 License Management»


Advertisement

Leave a Comment