- In answer to your first question, you can try below,
$license = Get-AzADSubscribedSku | Where-Object {$_.SkuPartNumber -eq "ENTERPRISEPACK"}
Get-AzADUser -Filter "AssignedLicenses/any(x:x/SkuId eq '$($license.SkuId)')" | Select-Object DisplayName, UserPrincipalName, ObjectId | Export-Csv -Path "C:\E3LicensedUsers.csv" -NoTypeInformation -Encoding UTF8
- You need to grant "User.Read.All" Delegated Permission and "User.Read.All", "Directory.Read.All" Application permissions to achieve this using Azure PowerShell principle.
Connect-MgGraph -ClientId "<ClientId>" -TenantId "<TenantId>" -CertificateThumbprint "<Thumbprint>"
Get-MgUser -All -Filter "AssignedLicenses/any(x:x/SkuId eq 'ENTERPRISEPACK')" | Select-Object DisplayName, UserPrincipalName, Id | Export-Csv -Path "C:\SPLicensedUsers.csv" -NoTypeInformation -Encoding UTF8
If you find my response helpful, please consider accepting this answer
and voting yes
to support the community. Thank you!