Pull a list of users and licenses from Azure AD.

Lisa 1 Reputation point
2021-02-04T18:51:48.447+00:00

I have an excel with userUPNs (20,000 or more). I need to see if those users have active licenses and what kind of license in Azure AD. Any ideas on how to do this?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,526 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 36,946 Reputation points Microsoft Employee
    2021-02-04T21:53:40.867+00:00

    Hi @Lisa ,

    To list all of the unlicensed users, you can use:

    Get-AzureAdUser | ForEach{ $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses | Measure).Count ; $i++) { If( [string]::IsNullOrEmpty(  $_.AssignedLicenses[$i].SkuId ) -ne $True) { $licensed=$true } } ; If( $licensed -eq $false) { Write-Host $_.UserPrincipalName} }  
    

    To list all licensed users, you can use:

    Get-AzureAdUser | ForEach { $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses | Measure).Count ; $i++) { If( [string]::IsNullOrEmpty(  $_.AssignedLicenses[$i].SkuId ) -ne $True) { $licensed=$true } } ; If( $licensed -eq $true) { Write-Host $_.UserPrincipalName} }  
    

    Or you can use the Microsoft Azure Active Directory Module for Windows PowerShell to do the same.

    To list all of the licenses assigned to a user, you can use:

    Get-MsolUser -UserPrincipalName <user account UPN> | Format-List DisplayName,Licenses  
    

    It looks like what you need to do is list all of the users in your subscription (Get-AzureAdUser -All $true) and then check the licenses for the particular UPNs.

    There's a blog post here that shows how to list all of the licensed users, then select their display name, UPN, license status, and License SKU and export it to a CSV.

    Get-MSOLUser -All | where {$_.isLicensed -eq $true} |select DisplayName,userprincipalname,islicensed,{$_.Licenses.AccountSkuId}| Export-CSV c:\O365UserList.csv –NoTypeInformation    
    

    I would also check out Vaibhav's script from this related thread, as well as the Powershell solution on this blog.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.