How to check permissions assigned to Managed Identity Access Token?

Najam ul Saqib 400 Reputation points
2025-05-14T07:32:35.1033333+00:00

Hi,

I have an automation account on which system-assigned managed identity is enabled. In Powershell, I can fetch the access token for this MI (by running run-job and during which fetching the MI's token) and later do actions on behalf of the identity once I authenticate using it with Connect-AzAccount

The question is, in the CLI/Powershell how can I check the permissions/roles assigned to the identity/token? I can obviously go to portal, and check IAM there but what if I want to achieve this in CLI?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ashok Gandhi Kotnana 10,115 Reputation points Microsoft External Staff Moderator
    2025-05-14T09:03:27.8233333+00:00

    HI @Najam ul Saqib,

    You can list the roles/permissions assigned to the managed identity using the Get-AzRoleAssignment cmdlet.

     Step 1: Get the Object ID of the system-assigned managed identity

     $automationAccount = Get-AzAutomationAccount -ResourceGroupName "<RG-Name>" -Name "<AutomationAccount-Name>" $miPrincipalId = $automationAccount.Identity.PrincipalId
    

    Artifacts below: -

    User's image

    Note: Principal Id is the Object ID of the managed identity in Azure AD.

    Step 2: List role assignments for the managed identity

    Get-AzRoleAssignment -ObjectId $miPrincipalId
    

     This will show all the role assignments and the scopes (e.g., subscription, resource group, specific resource) where they are applied.

     User's image Please let me know if you face any challenge here, I can help you to resolve this issue further

    Provide your valuable Comments.

    User's image

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    1 person found this answer helpful.

  2. Najam ul Saqib 400 Reputation points
    2025-06-05T07:19:26.5633333+00:00

    I was able to fetch the roles using this gist: https://gist.github.com/njmulsqb/536e052aec5aa3d1f3f28fd5bdc1eb7e

    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.