Skip to content

New-AzRoleAssignment returned an invalid status code 'BadRequest' #19374

@mattbalzan

Description

@mattbalzan

Description

On different GitHub runners, my action workflow runs the command:

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.

New-AzRoleAssignment: D:\a_temp\b31e73ff-178e-4971-83ff-3c0113c92680.ps1:27

New-AzRoleAssignment -ObjectId $objectID -RoleDefinitionName "Storage …

 |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 | Operation returned an invalid status code 'BadRequest'

Code that runs is as follows:

$objectID = (Get-AzVM -ResourceGroupName "${{env.RG}}" -Name "${{env.VMNAME}}").identity.principalid

Write-Output "Principal ID: $objectID"

New-AzRoleAssignment -ObjectId $objectID -RoleDefinitionName "Storage Blob Data Contributor" -ResourceGroupName "${{env.RG}}"               

On some runners my script works and then there are some runners that show the above error. Can anyone explain why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resource AuthorizationAzRole* in Az.Resourcescustomer-reportedneeds-author-feedbackMore information is needed from author to address the issue.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions