Forum Discussion
Power shell script which shows list of RBAC role, Azure resource and Username
- 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 Sorry, I didn't convey it properly it seems, my bad. Here is below output I was expecting from Powershell script.
Azure Resource name | SignInName | RoleDefinitionName |
keyvault | aaa@aaa.com | Conributor |
sql | aaa@aaa.com | Reader |
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}}
}
}
- printscreenJan 10, 2021Brass Contributor
ChrisBradshaw Does this script show the roles of users which are in groups too?
- ChrisBradshawJan 10, 2021Iron Contributor
printscreen Not as it stands- it shows the group name assigned to a role , but wouldn't resolve any members. To do that, we could look for any results from this script which had a value for a display name but not a sign in name. These could probably be interpreted as groups and fed into Get-ADGroupMember with the -recursive flag set.
- printscreenJan 10, 2021Brass Contributor
ChrisBradshawsomething like this?
ForEach ($Resource in Get-AzResource) {$RoleAssignments=Get-AZRoleAssignment -ResourceGroupName $Resource.ResourceGroupName -ResourceName $Resource.Name -ResourceType $resource.typeForEach ($RoleAssignment in $RoleAssignments){$new=Get-AzADGroupMember -DisplayName $RoleAssignments.DisplayNameforeach ($new in $RoleAssignment){$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}}}}}
- AlphaBetaGammaDec 22, 2020Brass Contributor
Thanks a lot ChrisChrisBradshaw