Get licenses applied to groups in new Azure AD using PowerShell

Featured image

In this blog, we will explore how to get the licenses assigned to each group in the new Azure AD group based licensing using PowerShell. In our previous blog, we have checked how to get the type of license applied(direct or group inherited) to the users.

Prerequisites Before starting the process, download and install Azure AD PowerShell module from this link. Then connecting to MsolService as global admin.

The license name that we get as output from PowerShell cmdlets are not user friendly, so we for better understanding we will map the license name with more user friendly names. Copy the below content to a text file named license-map.txt. We need to input this license map file path to our PowerShell script.

               @{
         "POWER_BI_STANDALONE" = "POWER BI STANDALONE" 
         "OFFICESUBSCRIPTION_FACULTY"= "Office 365 ProPlus for Faculty" 
         "RIGHTSMANAGEMENT_STANDARD_FACULTY"= "Azure Rights Management for faculty"       
         "ADALLOM_S_O365"= "POWER BI STANDALONE"       
         "CRMSTANDARD"= "CRM Online" 
         "EMS"= "Enterprise Mobility Suite" 
         "EMSPREMIUM" = "Enterprise Mobility + Security E5"
         "O365_BUSINESS_PREMIUM"= "Office 365 BUSINESS PREMIUM" 
         "DESKLESSPACK"= "Office 365 (Plan K1)" 
         "DESKLESSWOFFPACK"= "Office 365 (Plan K2)" 
         "LITEPACK"= "Office 365 (Plan P1)" 
         "EXCHANGESTANDARD"= "Office 365 Exchange Online Only" 
         "STANDARDPACK"= "Office 365 (Plan E1)" 
         "STANDARDWOFFPACK"= "Office 365 (Plan E2)" 
         "ENTERPRISEPACK"= "Office 365 Enterprise E3" 
         "ENTERPRISEPACKLRG"= "Office 365 Enterprise E3 LRG" 
         "ENTERPRISEWITHSCAL"= "Office 365 Enterprise E4" 
         "ENTERPRISEPREMIUM"= "Office 365 Enterprise E5" 
         "STANDARDPACK_STUDENT"= "Office 365 (Plan A1) for Students" 
         "STANDARDWOFFPACKPACK_STUDENT"= "Office 365 (Plan A2) for Students" 
         "ENTERPRISEPACK_STUDENT"= "Office 365 (Plan A3) for Students" 
         "ENTERPRISEWITHSCAL_STUDENT"= "Office 365 (Plan A4) for Students" 
         "EXCHANGESTANDARD_STUDENT"= "Exchange Online (Plan 1) for Students" 
         "STANDARDPACK_FACULTY"= "Office 365 (Plan A1) for Faculty" 
         "OFFICESUBSCRIPTION_STUDENT"= "Office ProPlus Student Benefit" 
         "STANDARDWOFFPACK_FACULTY"= "Office 365 Education E1 for Faculty" 
         "STANDARDWOFFPACK_IW_STUDENT"= "Office 365 Education for Students" 
         "STANDARDWOFFPACK_IW_FACULTY"= "Office 365 Education for Faculty" 
         "STANDARDWOFFPACK_STUDENT"= "Microsoft Office 365 (Plan A2) for Students" 
         "ENTERPRISEPACK_FACULTY"= "Office 365 (Plan A3) for Faculty" 
         "EOP_ENTERPRISE_FACULTY"= "Exchange Online Protection for Faculty" 
         "ENTERPRISEWITHSCAL_FACULTY"= "Office 365 (Plan A4) for Faculty" 
         "ENTERPRISEPACK_B_PILOT"= "Office 365 (Enterprise Preview)" 
         "STANDARD_B_PILOT"= "Office 365 (Small Business Preview)" 
         "CRMIUR"= "CRM for Partners" 
         "AAD_PREMIUM"= "Azure Active Directory Premium" 
         "STANDARDPACK_GOV"= "Microsoft Office 365 (Plan G1) for Government" 
         "STANDARDWOFFPACK_GOV"= "Microsoft Office 365 (Plan G2) for Government" 
         "ENTERPRISEPACK_GOV"= "Microsoft Office 365 (Plan G3) for Government" 
         "ENTERPRISEWITHSCAL_GOV"= "Microsoft Office 365 (Plan G4) for Government" 
         "DESKLESSPACK_GOV"= "Microsoft Office 365 (Plan K1) for Government" 
         "ESKLESSWOFFPACK_GOV"= "Microsoft Office 365 (Plan K2) for Government" 
         "EXCHANGESTANDARD_GOV"= "Microsoft Office 365 Exchange Online (Plan 1) only for Government" 
         "EXCHANGEENTERPRISE_GOV"= "Microsoft Office 365 Exchange Online (Plan 2) only for Government" 
         "SHAREPOINTDESKLESS_GOV"= "SharePoint Online Kiosk" 
         "EXCHANGE_S_DESKLESS_GOV"= "Exchange Kiosk" 
         "RMS_S_ENTERPRISE_GOV"= "Windows Azure Active Directory Rights Management" 
         "OFFICESUBSCRIPTION_GOV"= "Office ProPlus" 
         "MCOSTANDARD_GOV"= "Lync Plan 2G" 
         "SHAREPOINTWAC_GOV"= "Office Online for Government" 
         "SHAREPOINTENTERPRISE_GOV"= "SharePoint Plan 2G" 
         "EXCHANGE_S_ENTERPRISE_GOV"= "Exchange Plan 2G" 
         "EXCHANGE_S_ARCHIVE_ADDON_GOV"= "Exchange Online Archiving" 
         "EXCHANGE_L_STANDARD"= "Exchange Online (Plan 1)" 
         "MCOLITE"= "Lync Online (Plan 1)" 
         "SHAREPOINTLITE"= "SharePoint Online (Plan 1)" 
         "OFFICE_PRO_PLUS_SUBSCRIPTION_SMBIZ"= "Office ProPlus" 
         "EXCHANGE_S_STANDARD_MIDMARKET"= "Exchange Online (Plan 1)" 
         "MCOSTANDARD_MIDMARKET"= "Lync Online (Plan 1)" 
         "SHAREPOINTENTERPRISE_MIDMARKET"= "SharePoint Online (Plan 1)" 
         "SHAREPOINTWAC"= "Office Online" 
         "OFFICESUBSCRIPTION"= "Office ProPlus" 
         "YAMMER_MIDSIZE"= "Yammer" 
         "EXCHANGE_S_STANDARD"= "Exchange Online (Plan 2)" 
         "MCOSTANDARD"= "Lync Online (Plan 2)" 
         "SHAREPOINTENTERPRISE"= "SharePoint Online (Plan 2)" 
         "RMS_S_ENTERPRISE"= "Azure Active Directory Rights Management" 
         "YAMMER_ENTERPRISE"= "Yammer Enterprise" 
         "MCVOICECONF"= "Lync Online (Plan 3)" 
         "EXCHANGE_S_DESKLESS"= "Exchange Online Kiosk" 
         "SHAREPOINTDESKLESS"= "SharePoint Online Kiosk" 
         "EXCHANGEARCHIVE"= "Exchange Online Archiving" 
         "EXCHANGETELCO"= "Exchange Online POP" 
         "SHAREPOINTSTORAGE"= "SharePoint Online Storage" 
         "SHAREPOINTPARTNER"= "SharePoint Online Partner Access" 
         "PROJECTONLINE_PLAN_1"= "Project Online (Plan 1)" 
         "PROJECTONLINE_PLAN_2"= "Project Online with Project Pro for Office 365" 
         "PROJECT_CLIENT_SUBSCRIPTION"= "Project Pro for Office 365" 
         "VISIO_CLIENT_SUBSCRIPTION"= "Visio Pro for Office 365" 
         "INTUNE_A"= "Intune for Office 365" 
         "CRMTESTINSTANCE"= "CRM Test Instance" 
         "ONEDRIVESTANDARD"= "OneDrive" 
         "SQL_IS_SSIM"= "Power BI Information Services" 
         "BI_AZURE_P1"= "Power BI Reporting and Analytics" 
         "EOP_ENTERPRISE"= "Exchange Online Protection" 
         "PROJECT_ESSENTIALS"= "Project Lite" 
         "PROJECTPREMIUM"= "Project Online Premium" 
         "NBPROFESSIONALFORCRM"= "Microsoft Social Listening Professional" 
         "MFA_PREMIUM"= "Azure Multi-Factor Authentication" 
         "DMENTERPRISE"= "Microsoft Dynamics Marketing Online Enterprise" 
         "DESKLESS"= "Microsoft StaffHub" 
         "STREAM"= "Microsoft Stream" 
         "FLOW_P1"= "Microsoft Flow Plan 1" 
         "FLOW_P2"= "Microsoft Flow Plan 2" 
         "POWERFLOW_P1"= "Microsoft PowerApps Plan 1" 
         "POWERFLOW_P2"= "Microsoft PowerApps Plan 2" 
         "DYN365_ENTERPRISE_PLAN1"= "Dynamics 365 Plan 1 Enterprise Edition" 
         "AAD_PREMIUM_P2"= "Azure Active Directory Premium P2" 
         "POWER_BI_PRO"= "Power BI Pro" 
         "INFOPROTECTION_P2"= "Azure Information Protection Premium P2" 
         "WACONEDRIVESTANDARD"= "OneDrive for Business with Office Online" 
         "ADALLOM_STANDALONE"= "Microsoft Cloud App Security" 
         "RIGHTSMANAGEMENT"= "Azure Rights Management Premium" 
         }

Input Parameters Required $LicenseMappingPath : specify the license map file local path

Copy the below script to notepad and save it as group-list-with-license-assgined.ps1

``` {.black .top-margin .bottom-margin} function Get-GroupLicense { Param( [System.Management.Automation.PSCredential]$cred, [HashTable]$licname ) Connect-MsolService -Credential $cred $groups= Get-MsolGroup $GpLicenseList = @() foreach($group in $groups) { If($group.Licenses -ne $null) { $GpDetalis = “” | Select “GroupName”,”LicenseName”

     $lic=$group.Licenses.SkuPartNumber
      $GpLicName = ''
     foreach($lc in $lic)
     {
        If($GpLicName) {
                         if($licname.Item($lc.ToString()) -ne $null)
                         {
                         $GpLicName=$GpLicName + ";" + $licname.Item($lc.ToString())
                         }
                         Else
                         {
                         $GpLicName=$GpLicName + ";" + $lc.ToString()
                         }
 
                 } 
            Else {
                        if($licname.Item($lc.ToString()) -ne $null)
                         {
                         $GpLicName=$licname.Item($lc.ToString())
                         }
                         Else
                         {
                         $GpLicName= $lc.ToString()
                         }
                  }
     }
    $GpDetalis.GroupName = $group.Displayname
    $GpDetalis.LicenseName = "("+$GpLicName+")"
    $GpLicenseList+= $GpDetalis 
    $GpDetalis =$null
 }  }  return $GpLicenseList  }  #Don't forget the replace with your license map file path.  $LicenseMappingPath = 'C:\powershellquery\license-map.txt'  $content = ( Get-Content $LicenseMappingPath | Out-String )  $licname = ( Invoke-Expression $content )  $cred =Get-Credential  $Grouplist = Get-GroupLicense -cred $cred -licname $licname  $Grouplist  ```

Get all group with license name

{.black .top-margin .col-md-6} PS C:\PowershellQuery> & '.\ group-list-with-license-assgined.ps1'

Result