-1

Azure: Extend Psh command with two columns resource type & name

I am trying to write a Azure Psh command with two columns resource type & name and query the RBAC assignments for a user. I have these two tables, is there a way to merge the following two tables? Following is my current progress with the command:

Get-AzRoleAssignment -SignInName A12345@abc.com | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType} | Format-Table;
Get-AzRoleAssignment -SignInName A12345@abc.com | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.Scope | Select-Object -Property Name, ResourceType} | Format-Table

1 Answers1

0

You can use the below command to directly get the two information in one line :

Get-AzRoleAssignment -SignInName ansuman@xyz.com | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType} , {Get-AzResource -ResourceId $_.Scope | Select-Object -Property Name, ResourceType} | Format-Table

Update:

To prettify the Headers you can use this :

Get-AzRoleAssignment -SignInName ans@xyz.com | Select-Object -Property RoleDefinitionName, @{N='RoleDetails';E={Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType}} , @{L='ScopeDetails';E={Get-AzResource -ResourceId $_.Scope | Select-Object -Property Name, ResourceType}}

Output:

enter image description here

Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27
  • thanks :) How do I rename the column names here as they look ugly. I have tried the following and returns me an empty table: Get-AzRoleAssignment -SignInName T20821@eon.com | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType} | Format-Table @{L='Roles';E={RoleDefinitionName}},@{L='ResourceType';E={Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType}} – Amit Kumar Jan 05 '22 at 02:54