azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Get-AzureRmRoleAssignment with -RoleDefinitionId doesn't return assignments

Open marknettle opened this issue 8 years ago • 2 comments

Cmdlet(s)

Get-AzureRmRoleAssignment

PowerShell Version

5.1.15063.726

Module Version

5.1.1

OS Version

10.0.15063.726

Description

The Get-AzureRmRoleAssignment returns no assignments when using the -RoleDefinitionId parameter

Script/Steps for Reproduction

$role = Get-AzureRmRoleDefinition -Name Contributor
Get-AzureRmRoleAssignment -RoleDefinitionName $role.Name
Get-AzureRmRoleAssignment -RoleDefinitionId $role.Id

Expected Output

The two commands should return the same assignments

Observed Output

The second command returns no records, even when the first command returns multiple assignments

Similar behavior is observed whether or not -ObjectId and -Scope parameters are passed in, and whether a custom or standard role is used.

Debug Output

Other than request Ids and timestamps, the debug output from the two commands are nearly identical, but when -RoleDefinitionName is passed, there is an additional request, to graph.windows.net.

excerpt from Get-AzureRmRoleAssignment -ObjectId $sp.id -Scope $scope -RoleDefinitionName $role.Name

GetAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithObjectIdParameterSet'.
...
GET
https://management.azure.com//subscriptions/GUID/resourceGroups/RG/providers/Microsoft.Authorization/roleAssignments?$filter=principalId eq 'GUID'&api-version=2017-10-01-preview
...
GET
https://management.azure.com//subscriptions/GUID/resourceGroups/RG/providers/Microsoft.Authorization/roleDefinitions?$filter=atScopeAndBelow()&api-version=2015-07-01
...
POST https://graph.windows.net/GUID/getObjectsByObjectIds?api-version=1.6
...
AzureQoSEvent: CommandName - Get-AzureRmRoleAssignment; IsSuccess - True; Duration - 00:00:01.3861522; Exception - ;

excerpt from Get-AzureRmRoleAssignment -ObjectId $sp.id -Scope $scope -RoleDefinitionId $role.Id

GetAzureRoleAssignmentCommand begin processing with ParameterSet 'RoleIdWithScopeAndObjectIdParameterSet'.
...
GET
https://management.azure.com//subscriptions/GUID/resourceGroups/RG/providers/Microsoft.Authorization/roleAssignments?$filter=principalId eq 'GUID'&api-version=2017-10-01-preview
...
GET
https://management.azure.com//subscriptions/GUID/resourceGroups/RG/providers/Microsoft.Authorization/roleDefinitions?$filter=atScopeAndBelow()&api-version=2015-07-01
...
AzureQoSEvent: CommandName - Get-AzureRmRoleAssignment; IsSuccess - True; Duration - 00:00:00.6730768; Exception - ;

marknettle avatar Jan 11 '18 03:01 marknettle

@marknettle Thanks for the repro,will look into it

darshanhs90 avatar Jan 11 '18 21:01 darshanhs90

Fixed in the PR linked above, and will be included in the next release.

maddieclayton avatar Feb 22 '18 22:02 maddieclayton