I’ve given the automation account a system assigned managed identity. Successfully used these to set the context :
$AzureContext = (Connect-AzAccount -Identity).context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
But when I use this inside the runbook to get the jobs :
Get-AzAutomationJob -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -RunbookName $runbookName -DefaultProfile $AzureContext
it returns nothing. No error, so command must execute, but doesn’t return any results.
What I noticed is that the context which returns when connecting with the managed identity, doesn’t have values for Name and Subscription. It only has values for Account, Environment and Tenant. Could this be the problem?
2
Answers
Well the problem turned out quite trivial. I had to give permissions for the subscription to the managed identity. Even though I'm not using this identity to access any resources, it still needs permissions to read the subscription data. Unlike the Run As account which doesn't need any permissions. So "problem" solved. Thank you for your time and desire to help!
I just ran a short test with your commands in the portal powershell and used ‘Get-AzAutomationJob’ with two runbooks. One of them has the status set to ‘Published’ and the other to ‘New’. The new one has no prior jobs that ran.
yields the result:
and several more showing in the portal.
whereas
Gives back nothing.
After creating a simple scheduled job in the ‘provision-portal’ runbook I received output when running the same command again:
Can you check the Authoring status and see if it is published and if any jobs are running or ran?
Kind regards