azure-powershell
azure-powershell copied to clipboard
New-AzRoleAssignment returned an invalid status code 'BadRequest'
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?
It seems error is swallowed by code. Please turn on debug message $DebugPreference = "Continue" to get what error message is from service.
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!
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! :)