Office 365 License Report using PowerShell

We can use the Azure AD powershell cmdlet Get-MsolUser to get all office 365 users. This command also returns the license based property IsLicensed and Licenses (applied license details).

Note: Before proceed, Install and Configure Azure AD PowerShell

Run the below command to get all the office 365 users.

Get-MsolUser -All  | Select-Object UserPrincipalName, DisplayName, isLicensed

The below command returns only licensed office 365 users.

Get-MsolUser -All | Where-Object { $_.isLicensed -eq $true } |
Select-Object UserPrincipalName, DisplayName, Department

You can also extract what are the licenses has been assigned to every users.

Get-MSOLUser -All | Where-Object { $_.isLicensed -eq $true } |
Select-Object UserPrincipalName, DisplayName, {$_.Licenses.AccountSkuId}

Run the below command to export all the licensed users and applied license details to csv file.

Get-MSOLUser -All | Where-Object { $_.isLicensed -eq $true } |
Select-Object UserPrincipalName, DisplayName, {$_.Licenses.AccountSkuId} |
 Export-CSV "C:\office-365-users-license.csv" -NoTypeInformation -Encoding UTF8

You can read this technet article: https://technet.microsoft.com/en-us/library/dn771771.aspx to get fine-tuned license report, like all licensed users who are enabled for specific license plan.


Advertisement

2 thoughts on “Office 365 License Report using PowerShell”

    • For the specific users list, you can keep the users’ UserPrincipalName in a CSV file and try the following commands.

      $CSVRecords = Import-CSV “C:\Temp\AzureADUsers.csv”

      $Result=@() #Array to add the status result

      #Iterate CSVRecords (users) one by one and get license details
      Foreach($CSVRecord in $CSVRecords)
      {
      $UserUPN = $CSVRecord.’UserPrincipalName’
      Try
      {
      $UserObj = Get-MsolUser -UserPrincipalName $UserUPN

      #Add user info to the result array
      $Result += New-Object PSObject -property $([ordered]@{
      UserPrincipalName = $UserUPN
      UserName = $UserObj.DisplayName
      IsLicensed= $UserObj.IsLicensed
      })
      }
      catch
      {
      Write-Host “Failed: $_”
      }
      }

      #Get only licensed users from the given list of users
      $Result | Where-Object { $_.IsLicensed -eq $true }

      Reply

Leave a Comment