How to pull users details with licenses details

Prince Chauhan 0 Reputation points

Hi All,

We have more than 1000 users in our environment. We want to pull the users details with licenses assignment, how many license are assigned per user.

Example shown below.

User's image

Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,184 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Harpreet Singh Matharoo 7,596 Reputation points Microsoft Employee

    Hello Prince,

    Thank you for reaching out. I would like to inform you that you can use following script to pull User and Assigned License details:

    $Result = @() #Result array
    #Get all subscribed license Skus to Microsoft services
    $AllSkus= Get-AzureADSubscribedSku
    #Get all Azure AD Users with the required properties
    $AllUsers = Get-AzureADUser -All $true | Select DisplayName, UserPrincipalName, AssignedLicenses, AssignedPlans, ObjectId
    #Iterate users one by one and resolve the license details
    ForEach ($User in $AllUsers)
    $AssignedLicenses = @();
    $LicensedServices = @();
    if($User.AssignedLicenses.Count -ne 0)
    #Resolve license SKU details
    ForEach($License in $User.AssignedLicenses)
    $SkuInfo = $AllSkus | Where { $_.SkuId -eq $License.SkuId}
    $AssignedLicenses += $SkuInfo.SkuPartNumber;
    #Resolve assigned service plans
    ForEach($ServicePlan in $User.AssignedPlans)
    $LicensedServices += $ServicePlan.Service;
    #Add user detail to $Result array one by one
    $Result += New-Object PSObject -property $([ordered]@{
    UserName = $User.DisplayName
    UserPrincipalName = $User.UserPrincipalName
    UserId= $User.ObjectId
    IsLicensed  = if ($User.AssignedLicenses.Count -ne 0) { $true } else { $false }
    Licenses = $AssignedLicenses -join ","
    LicensedServices = ($LicensedServices | Sort-Object | Get-Unique)  -join ","
    #Export All Microsoft 365 Users report to CSV
    $Result | Export-CSV "C:\Temp\Microsoft365Users.CSV" -NoTypeInformation -Encoding UTF8

    I hope this helps and hence would request you to please "Accept the answer" if the information helped you. This will help us and others in the community as well.

  2. Prince Chauhan 0 Reputation points

    Hi Harpreet, Good Day! If we want fetch the user location with above details should we add the below line under the result. UserCity= $User.City

    0 comments No comments