Users: Assigned Licenses

Retrieving all users assigned an Azure AD (Entra ID) license using Microsoft Graph.


Connect-MgGraph -Scopes @('User.Read.All')
$params = @{
    'All'              = $true;
    'Filter'           = 'assignedLicenses/$count ne 0';
    'CountVariable'    = 'userCount';
    'ConsistencyLevel' = 'eventual';
    'PageSize'         = '999';
$users = Get-MgUser @params


Microsoft Graph SDK for PowerShell

Install-Module Microsoft.Graph -AllowClobber -Force


Using the Microsoft Graph Command Line Tools Enterprise Application:

Connect-MgGraph -Scopes @('')

Using an existing Access Token:

Connect-MgGraph -AccessToken (ConvertTo-SecureString 'ey..' -AsPlainText -Force)

Using an Application Registration (Platform: Mobile and desktop applications, redirect http://localhost):

Connect-MgGraph -ClientId 'abc..' -TenantId 'abc..'

Using a ClientId and Secret (Password):

$tenantId = ''
$clientId = ''
$secret = ConvertTo-SecureString '' -AsPlainText -Force
$secretCredential = New-Object System.Management.Automation.PSCredential ($clientId, $secret)
$params = @{
    'SecretCredential' = $secretCredential
    'TenantId'         = $tenantId
Connect-MgGraph @params