Skip to content
kendaleiv.com
Go back

Retrieving ObjectIds In An Azure Active Directory Group Using Azure CLI

Using Azure CLI we can retrieve a list of objectIds in a Azure Active Directory group.

Setup

Install the Azure CLI if it’s not already installed.

If you aren’t currently logged in with Azure CLI run:

az login

Retrieving ObjectIds

Now, you’re ready to get the objectIds!

az ad group member list --group "GROUP_NAME_HERE" --query "[].{displayName: displayName, userPrincipalName: userPrincipalName, objectId: objectId}" --output table
DisplayName  UserPrincipalName  ObjectId
-----------  -----------------  ------------------------------------
Test User 1  test1@example.com  00000000-0000-0000-0000-000000000001
Test User 2  test2@example.com  00000000-0000-0000-0000-000000000002

If you’re looking for a comma separated value:

az ad group member list --group "GROUP_NAME_HERE" --query "[].objectId | {objectIds: join(',', @)}"
{
  "objectIds": "00000000-0000-0000-0000-000000000001,00000000-0000-0000-0000-000000000002"
}

Hi, I'm Ken

Jesus follower, husband, father, software engineer.

I share things I've learned, problems I've worked through, and notes worth keeping — mostly about software, sometimes about other things.

Browse my posts, explore my speaking engagements, or learn more about me.


Previous Post
Naming Durable Functions With Prefixes For Application Insights Filtering
Next Post
Setting Regex Timeout Globally Using .NET 6.0 With C#