i like your question
How to read Entra ID user data by automation account?
I have a runbook in an automation account with managed identity. I want this runbook to read information about federated users and groups from Entra ID. I want it to do it using "Connect-MgGraph -Identity".
I got granted privileges "Directory.Read.All, User.Read.All, GroupMember.Read.All" to the automation account identity, but when calling "Connect-MgGraph -Identity" I still get error "Invalid JWT access token."
What is missing and why?
Update: The privileges are granted by Admin, this is not the issue.
Azure Automation
2 answers
Sort by: Most helpful
-
-
Sandhya Kommineni 245 Reputation points Microsoft External Staff Moderator
2025-08-26T07:20:25.09+00:00 Hi PPA Richard Vaněk, thanks for sharing details
Granting permissions to the Microsoft Graph (GraphAggregatorService) app is not required and not correct. That object represents Graph itself you never assign roles to it.
Try recommended steps to resolve the issue:
1.Verify the token audience
From inside your runbook, dump the token that
Connect-MgGraph -Identity
gets:Connect-MgGraph -Identity (Get-MgContext).AccessToken | Out-File "D:\home\LogFiles\graph_token.txt"
Then decode it at jwt.ms. Check the
aud
(audience) claim it must behttps://graph.microsoft.com
.If it’s something else (like
https://management.azure.com
), then Graph will reject it.2.Check the app role assignments
Sometimes people add them in API permissions but forget to add them in App role assignments only the latter works for managed identities.Navigate to Entra ID → Enterprise Applications → [your Automation Account MI] → App role assignments, and confirm your roles
3.Explicitly select scopes when connecting
Sometimes
Connect-MgGraph -Identity
without-Scopes
fails to attach roles properly.Try connecting,Connect-MgGraph -Identity -Scopes "Directory.Read.All","User.Read.All","GroupMember.Read.All"
4.Retry with user-assigned MI (if possible)
If you’re using a system-assigned MI, test by attaching a user-assigned MI to the Automation Account and then:
Connect-MgGraph -Identity -ClientId <user-assigned-mi-client-id>
This helps isolate whether it’s a token issue with the system-assigned identity.
I hope this helps you resolve the issue. If you need any further assistance, I am happy to assist.