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.