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

New-AzRoleAssignment returned an invalid status code 'BadRequest'

Open mattbalzan opened this issue 3 years ago • 2 comments

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?

mattbalzan avatar Sep 01 '22 16:09 mattbalzan

It seems error is swallowed by code. Please turn on debug message $DebugPreference = "Continue" to get what error message is from service.

dingmeng-xue avatar Sep 03 '22 01:09 dingmeng-xue

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

ghost avatar Sep 10 '22 02:09 ghost

logs_59.zip

Morning @dingmeng-xue, this just happened now - I have uploaded the logs with the Debug Prefs on. Yesterday I ran 3 workflows without any issues and now the error has popped up today. Let me know if you need anything else! :)

mattbalzan avatar Sep 28 '22 09:09 mattbalzan