Get-AzRoleAssignment shows empty RoledefinitionName for custom roles when not using Scope or ResourceGroup parameter
Description
Since the change of the Powershell module to version 7.X the Get-AzRoleAssignment cmdlet shows a blank RoledefinitionName for role assignments that target a custom role created at Subscription or Resource Group scope. When the cmdlet is executed with the use of the Scope or ResourceGroup parameter it does show it.
PS C:\> Get-AzRoleAssignment | group-object RoledefinitionName
WARNING: We have migrated the API calls for this cmdlet from Azure Active Directory Graph to Microsoft Graph.
Visit https://go.microsoft.com/fwlink/?linkid=2181475 for any permission issues.
Count Name Group
----- ---- -----
2 {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment, Microsoft.A…
10 Contributor {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment, Microsoft.A…
5 Owner {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment, Microsoft.A…
4 Reader {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment, Microsoft.A…
1 Resource Policy Contribu… {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment}
1 Storage Table Data Reader {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment}
1 User Access Administrator {Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment}
Also when the parameter RoleDefinitionName is used in combination with the name of the role definition no results are returned.
PS C:\> Get-AzRoleAssignment -RoleDefinitionName 'Custom Role - RG Reader SUB SCOPE'
WARNING: We have migrated the API calls for this cmdlet from Azure Active Directory Graph to Microsoft Graph.
Visit https://go.microsoft.com/fwlink/?linkid=2181475 for any permission issues.
It does work when you specify the scope.
PS C:\> Get-AzRoleAssignment -RoleDefinitionName 'Custom Role - RG Reader SUB SCOPE' -Scope '/subscriptions/6ad53578-207d-4c9a-b6ea-1f760e828216'
WARNING: We have migrated the API calls for this cmdlet from Azure Active Directory Graph to Microsoft Graph.
Visit https://go.microsoft.com/fwlink/?linkid=2181475 for any permission issues.
RoleAssignmentName : fc149990-ac14-4ccd-8c6e-deb8157b06d3
RoleAssignmentId : /subscriptions/6ad53578-207d-4c9a-b6ea-1f760e828216/resourceGroups/TEMPIASM/providers/Microsoft.Au
thorization/roleAssignments/fc149990-ac14-4ccd-8c6e-deb8157b06d3
Scope : /subscriptions/6ad53578-207d-4c9a-b6ea-1f760e828216/resourceGroups/TEMPIASM
DisplayName : Ruud van den Hooff
..............
This is a change compared to version 6.X of this module as in that it will display the RoledefinitionName or will return results when you use the RoledefinitionName parameter without specifying a scope.
Issue script & Debug output
When you run a Get-AzRoleAssignment without the Resource Group or Scope parameter the body does not contain the custom roles that has an assignable scope set to subscription or resource group.
============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-request-id : 80c81db7-62de-41d3-b7ac-77ef197c6f57
X-Content-Type-Options : nosniff
Strict-Transport-Security : max-age=31536000; includeSubDomains
Set-Cookie : x-ms-gateway-slice=Production; path=/; secure; samesite=none; httponly
x-ms-ratelimit-remaining-tenant-reads: 11999
x-ms-correlation-request-id : bde29490-87f4-47dd-b5ed-0ba946bf8acb
x-ms-routing-request-id : WESTEUROPE:20220201T124602Z:bde29490-87f4-47dd-b5ed-0ba946bf8acb
Date : Tue, 01 Feb 2022 12:46:02 GMT
Body:
{
"value": [
{
"properties": {
"roleName": "Avere Cluster Create",
"type": "CustomRole",
"description": "Avere cluster create role used by the Avere controller to create a vFXT cluster.",
"assignableScopes": [
.......
#When you use the ResourceGroup parameter it does include the RoleDefinition in the verbose output.
{
"properties": {
"roleName": "Custom Role - RG Reader SUB SCOPE",
"type": "CustomRole",
"description": "Subscription Level Deployment of a Role Definition",
"assignableScopes": [
"/subscriptions/6ad53578-207d-4c9a-b6ea-1f760e828216"
],
"permissions": [
{
"actions": [
"Microsoft.Resources/subscriptions/resourceGroups/read"
],
"notActions": [
"*"
],
"dataActions": [],
"notDataActions": []
}
],
"createdOn": "2022-01-28T13:15:24.1265962Z",
"updatedOn": "2022-01-28T13:15:24.1265962Z",
"createdBy": "f9b4dccc-09e3-47c6-a7fb-4269a2623160",
"updatedBy": "f9b4dccc-09e3-47c6-a7fb-4269a2623160"
},
"id": "/subscriptions/6ad53578-207d-4c9a-b6ea-1f760e828216/providers/Microsoft.Authorization/roleDefinitions/0ed6f4fd-b2a4-528a-842a-7b3bb3488972",
"type": "Microsoft.Authorization/roleDefinitions",
"name": "0ed6f4fd-b2a4-528a-842a-7b3bb3488972"
}
Environment data
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.7.1 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefa…
Script 5.2.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, G…
powershell
Error output
No error, new and unexpected behavior since the change to Graph API.
Same here. I have also found that the RoleDefinitionId is not consistent. It sometimes outputs a guid for the id, other times it outputs the full id if I try to get the roleassignment with the objectid parameter. For example: With full id:
RoleAssignmentName : 9071ec8d-b825-468d-a4a2-7eafa6a72c6d
RoleAssignmentId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments/9071ec8d-b825-468d-a4a2-7eafa6a72c6d
Scope : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
DisplayName : TestGroupName
SignInName :
RoleDefinitionName : Contributor
RoleDefinitionId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleDefinitions/ec5e1727-4519-4e56-adbf-3db9676b0b6b
ObjectId : 0eedd361-910e-423f-86c3-0b634a6f4b65
ObjectType : Group
CanDelegate : False
Description :
ConditionVersion :
Condition :
With only guid:
RoleAssignmentName : 139afb1b-43ee-4302-8074-abca3b7750c4
RoleAssignmentId : /subscriptions/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy/providers/Microsoft.Authorization/roleAssignments/139afb1b-43ee-4302-8074-abca3b7750c4
Scope : /subscriptions/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
DisplayName : TestGroupName
SignInName :
RoleDefinitionName :
RoleDefinitionId : c38664e7-9fcc-44c6-b426-4dc638d27066
ObjectId : 401bbdf7-5212-4d33-91a8-5727f0e2e535
ObjectType : Group
CanDelegate : False
Description :
ConditionVersion :
Condition :
@RuvdH and @rzilahi , could you check current account has sufficient permission to access MSGraph?
Since Az 7.0, we migrated AAD feature to MSGraph API. If client has no permission, the property from MSGraph API won't be shown up. We have listed used MSGraph API on doc https://docs.microsoft.com/en-us/powershell/module/az.resources/get-azroleassignment?view=azps-7.1.0
Is Global Admin high enough :) No really, I don't get this info back with custom roles even if I am a global admin. That app that we also used to test has Directory.Read.All permission.
Thanks for reporting @RuvdH and @rzilahi .
We are fixing this issue and new version of Az.Resources will be available in next release (about 03/01). In new version,
- RoleDefinitionName will show correctly for custom roles
- RoleDefinitionId will be unified as GUID.