fetch information from AzureAD

Glenn Maxwell 11,621 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.
Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,611 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,147 questions
Microsoft Entra
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,291 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lakshan Umesh 21 Reputation points
    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 comments No comments

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.