Get disabled Azure ADUsers with an active license

View licensed and unlicensed Microsoft 365 users.

### To view the list of all disabled licensed user accounts in your organization, run the following command:
Get-AzureAdUser -All $true -Filter "AccountEnabled eq false" |
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} }

### To view the list of all unlicensed user accounts in your organization, run the following command:
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 view the list of all licensed user accounts in your organization run the following command:
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} }