Hi @Neel Darji
Yes, it's possible to do that by reading the subscription IDs from a CSV file. Then, iterating over each subscription, retrieving the associated roles and exporting them to separate CSV files.
Create a CSV file (subscriptionlist.csv) with a column named SubscriptionId
containing the subscription IDs.
Use below sample PowerShell code.
Connect-AzAccount
$subscriptions = Import-Csv -Path "C:\subscriptionlist.csv"
foreach ($sub in $subscriptions) {
$subscriptionId = $sub.SubscriptionId
$roles = Get-AzRoleDefinition -Scope "/subscriptions/$subscriptionId" | Select-Object Name, Id, description
$roles | Export-Csv -Path "c:\roles_$subscriptionId.csv" -NoTypeInformation
Write-Output "Roles for subscription $subscriptionId exported to roles_$subscriptionId.csv"
}
Hope this helps. Do let us know if you any further queries.
Thanks,
Navya.