Forum Discussion

AlphaBetaGamma's avatar
AlphaBetaGamma
Brass Contributor
Dec 21, 2020
Solved

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?   
  • ChrisBradshaw's avatar
    ChrisBradshaw
    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}}
     }
    }

     

Resources