fetch information from AzureAD

Glenn Maxwell 12,876 Reputation points
2024-11-23T01:56:23.3433333+00:00

Hi All,

I have two questions related to Object IDs:

  1. I want to export all my users' Object IDs from Azure AD for regular users(regular mailboxes) using PowerShell and export them to csv file. OR, I want to export Object IDs for all users in Azure AD who have a Microsoft 365 E3 license assigned. Please guide me on how to fetch this information using PowerShell syntax.
  2. If I need to fetch the above information using an Azure Service Principal (i.e., App Registration), what API permissions are required? Please guide me.
Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,188 questions
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Entra | Other
{count} votes

Accepted answer
  1. Lakshan Umesh 181 Reputation points MVP
    2024-11-23T02:14:34.41+00:00
    • 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!


0 additional answers

Sort by: Most 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.