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 [email protected] | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.RoleAssignmentID | Select-Object -Property Name,ResourceType} | Format-Table;
Get-AzRoleAssignment -SignInName [email protected] | Select-Object -Property RoleDefinitionName, {Get-AzResource -ResourceId $_.Scope | Select-Object -Property Name, ResourceType} | Format-Table
You can use the below command to directly get the two information in one line :
Get-AzRoleAssignment -SignInName [email protected] | 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 [email protected] | 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: