Share via

Exporting Subscriptions and Role Assignments Issue

H Raja 346 Reputation points
2026-03-30T16:13:35.5033333+00:00

I'm trying to Export all my Subscriptions and Role Assignments in my tenants. I've tried via PowerShell and using Co-Pilot :-). hopefully Screenshot has some justice. Each time it runs it shows error 'Continnous access evaluation resulted in challenge............ for each subscription.

Anyone that has a script that can give me for each Subscription, the roles assignment assigned and details of group or SPN assigned. thanks

8949c86b-4b94-4aea-92ae-dde4a67220d0

Azure Role-based access control
Azure Role-based access control

An Azure service that provides fine-grained access management for Azure resources, enabling you to grant users only the rights they need to perform their jobs.

0 comments No comments

Answer accepted by question author
  1. Sridevi Machavarapu 26,355 Reputation points Microsoft External Staff Moderator
    2026-03-31T08:38:36.04+00:00

    Hello H Raja,

    The error you’re seeing is due to CAE interrupting the session during a long run, not an issue with your script.

    The clean way around it is to use a service principal instead of interactive login.

    Create an app registration and assign:

    • Reader on all subscriptions (or at management group level)
    • Directory Reader (optional, for resolving names)

    Then run this:

    $path = "C:\Temp\RBAC_Export.csv"
    
    $tenantId = "<tenant-id>"
    $appId    = "<app-id>"
    $secret   = "<client-secret>"
    
    $secureSecret = ConvertTo-SecureString $secret -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential($appId, $secureSecret)
    
    Connect-AzAccount -ServicePrincipal -Tenant $tenantId -Credential $cred
    
    if (!(Test-Path "C:\Temp")) {
        New-Item -ItemType Directory -Path "C:\Temp" | Out-Null
    }
    
    $result = @()
    
    foreach ($sub in Get-AzSubscription) {
    
        if ($sub.State -ne "Enabled") { continue }
    
        Set-AzContext -SubscriptionId $sub.Id | Out-Null
    
        foreach ($a in Get-AzRoleAssignment -Scope "/subscriptions/$($sub.Id)") {
            $result += [PSCustomObject]@{
                SubscriptionName = $sub.Name
                SubscriptionId   = $sub.Id
                RoleName         = $a.RoleDefinitionName
                PrincipalName    = $a.DisplayName
                PrincipalType    = $a.ObjectType
                Scope            = $a.Scope
            }
        }
    }
    
    $result | Export-Csv $path -NoTypeInformation
    
    Write-Host "Export completed: $path"
    

    This will run through all subscriptions and export everything into a single file without the CAE interruptions.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-30T16:13:55.6+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    For exporting subscription-level role assignments with full principal details, there are two supported approaches in the provided material: using the Azure portal for Azure RBAC roles and using Microsoft Entra ID for directory roles. Both avoid the continuous access evaluation issue seen in custom scripts.

    1. Export Azure RBAC role assignments per subscription in the Azure portal

    This gives all role assignments (built‑in and custom) at a chosen scope, including users, groups, and service principals.

    Steps:

    1. In the Azure portal, go to All services and select the scope:
      • Subscriptions → choose the subscription whose assignments are needed.
    2. Open the subscription and select Access control (IAM).
    3. Select Download role assignments to open the download pane.
    4. Choose which assignments to include:
      • Inherited – include assignments inherited from higher scopes.
      • At current scope – include assignments defined directly on the subscription.
      • Children – include assignments on child resource groups and resources.
    5. Select file format CSV (best for analysis) or JSON.
    6. Provide a file name and select Start.

    The CSV/JSON output contains, for each assignment:

    • Role definition
    • Scope
    • Principal information (user, group, or service principal)
    • Additional metadata

    If directory read permissions are missing (for example, no Directory Readers role), the DisplayName, SignInName, and ObjectType columns will be blank; in that case, grant appropriate directory read permissions and re-export.

    Repeat this for each subscription in the tenant to build a complete inventory of subscription-level Azure RBAC assignments.

    1. Export Microsoft Entra role assignments (directory roles)

    If the requirement also includes Microsoft Entra directory roles (Global Administrator, etc.), these can be exported centrally.

    To export all active directory role assignments across all roles:

    1. In the Microsoft Entra admin center, go to Entra IDRoles & admins.
    2. On Roles and administrators, select All roles.
    3. Select Download assignments.
    4. Specify a file name and select Start bulk operation.

    A CSV file is downloaded listing all role assignments at all scopes for all directory roles, including the assigned user, group, or service principal.

    To export assignments for a single directory role:

    1. On Roles and administrators, select the specific role.
    2. Select Download assignments (or Export if using PIM experience).
    3. A CSV file is downloaded listing all assignments for that role at all scopes.
    4. Export user and group assignments to service principals (enterprise apps)

    For a tenant-wide view of which users and groups are assigned to enterprise applications (service principals), Microsoft Entra PowerShell can export this to CSV:

    1. Connect with sufficient permissions (for example, Cloud Application Administrator):
         Connect-Entra -Scopes 'Directory.Read.All', 'Application.Read.All'
      
    2. Run the documented script that:
      • Retrieves all service principals.
      • Collects user and group assignments for each service principal.
      • Exports to CSV with service principal name, assigned users, and assigned groups.

    This complements the Azure RBAC export by giving application assignment details for all service principals in the tenant.

    Using these built-in export capabilities avoids the continuous access evaluation challenges that can interrupt long-running custom scripts and provides the requested mapping of subscriptions to role assignments and principals (users, groups, and service principals).


    References:


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.