I have been working to convert our runbooks in Azure to use Managed Identity and keep running into an error when running these commands from Azure. They run fine directly on the machines with the Hybrid Workers and if the Runbook is run directly on the hybrid worker but in many cases the runbooks start on Azure itself.
Section of code:
Connect-AzAccount -Identity
Add-AzAccount -Identity
Error Message Example: Add-AzAccount : An error occurred while sending the request...[Connect-AzAccount], HttpRequestException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Searching thru I wasn't able to find a solution only similar problems, I have also updated these module so the current Modules loaded are: AZAccounts 1.9.1 AZResources 2.3.0
you can just have an if condition (based on some arbitrary check) and if it fails - run the managed identity login, otherwize certificate login, that way you dont have to have 2 version on the same script