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.