Unable to get eligible groups for user accounts while using MgGraph powershell module

Basteas Dimitris 20 Reputation points
2026-03-17T20:32:49.97+00:00

I' m using the below script in order to retrieve the eligible groups that a user account is member of:

Connect-MgGraph -Scopes "PrivilegedEligibilitySchedule.Read.AzureADGroup","Group.Read.All","User.Read.All"

$user = Get-MgUser -UserId ******@myDomain.com

Get-MgIdentityGovernancePrivilegedAccessGroupEligibilityScheduleInstance -Filter "principalId eq '$($user.Id)'"

For my account it works fine.

For any other account I' m getting :

Status: 403 (Forbidden)

ErrorCode: UnauthorizedAccessException

I have the Global admin role , and I have grant consent the permissions on scope above for the tenant.

Microsoft Security | Microsoft Entra | Microsoft Entra ID

Answer accepted by question author
Rukmini 43,705 Reputation points Microsoft External Staff Moderator
2026-03-18T19:13:13.3133333+00:00

Hello Carolyne-3676

There is no direct API in Microsoft Graph API to retrieve all eligible groups for another user using only principalId. This is by design.

Since group IDs are required, you must reverse the lookup:

  1. Get all PIM-enabled groups (or all groups if needed)
  2. Query eligibility per group + user:
       -Filter "principalId eq '<user-id>' and groupId eq '<group-id>'"
    

Maintain or retrieve a list of PIM-enabled groups only (not all groups)

  1. Loop through those groups for each user
  2. This is the only scalable and supported method

Let me know if any further queries - feel free to reach out!

Hello Carolyne-3676 If the resolution was helpful, kindly take a moment to click on 210246-screenshot-2021-12-10-121802.pngand click on Yes for was this answer helpful. And, if you have any further query do let us know.

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-03-17T20:33:01.9333333+00:00

    The 403 UnauthorizedAccessException occurs because the delegated permissions in the Connect-MgGraph call are not sufficient for reading other users’ PIM eligibility schedules across the tenant, even with Global Administrator role.

    For similar Graph/PIM and directory-wide operations, adding the Directory.AccessAsUser.All delegated permission and re‑consenting resolves the “insufficient privileges”/403 issues.

    Adjust the sign-in as follows:

    Connect-MgGraph -Scopes \
      "PrivilegedEligibilitySchedule.Read.AzureADGroup",\
      "Group.Read.All",\
      "User.Read.All",\
      "Directory.AccessAsUser.All"
    

    Then re-run:

    $user = Get-MgUser -UserId '******@myDomain.com'
    Get-MgIdentityGovernancePrivilegedAccessGroupEligibilityScheduleInstance -Filter "principalId eq '$($user.Id)'"
    

    If consent was previously granted without Directory.AccessAsUser.All, an admin must grant consent again including this scope.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.