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 22, 2020Iron Contributor
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}}
}
}
AlphaBetaGamma
Dec 22, 2020Brass Contributor
Thanks a lot ChrisChrisBradshaw