Forum Discussion
AlphaBetaGamma
Dec 21, 2020Brass Contributor
Power shell script which shows list of RBAC role, Azure resource and Username
Hi, Can anyone please help me with a powershell script which shows list consisting of RBAC role, Azure resource & username to whom it is allocated to?
- Dec 22, 2020
AlphaBetaGamma Thanks- that makes sense.
The following script should do something like that, by looping through the resources and then a nested loop through the role assignments. I've included the "Display Name" field as well in case you have any roles assigned to groups- they just have a blank entry for "SignInName".foreach ($Resource in Get-AzResource) { $RoleAssignments=Get-AZRoleAssignment -ResourceGroupName $Resource.ResourceGroupName -ResourceName $Resource.Name -ResourceType $resource.type ForEach ($RoleAssignment in $RoleAssignments){ $Resource | Select-Object @{Name="Azure Resource name";Expression={$Resource.Name}}, @{Name="SignInName";Expression={$RoleAssignment.SignInName}}, @{Name="DisplayName";Expression={$RoleAssignment.DisplayName}}, @{Name="RoleDefinitionName";Expression={$RoleAssignment.RoleDefinitionName}} } }
ChrisBradshaw
Dec 21, 2020Iron Contributor
AlphaBetaGamma How about this, using the Get-AzRoleAssignment cmdlet:
Get-AzRoleAssignment | Select-Object RoleDefinitionName, Scope , DisplayName
Output will look something like this
RoleDefinitionName Scope DisplayName
------------------ ----- -----------
Contributor /subscriptions/(guid)/resourcegroups/myresourcegroup Bob
Reader /subscriptions/(guid)/resourcegroups/myresourcegroup/myvm Jim
Contributor /subscriptions/(guid)/resourcegroups/myresourcegroup/myvm Sal
AlphaBetaGamma
Dec 21, 2020Brass Contributor
Thanks for your response, Yeah, i have tried this. But I was trying to get exact resource name against each RABC role and the username. ChrisBradshaw