Every so often, we find an Azure Automation Runbook fails with the following error:
Get-AutomationPSCredential : The term 'Get-AutomationPSCredential' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:9 + $cred = Get-AutomationPSCredential -Name SqlJobRunner + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AutomationPSCredential:String) , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Different runbooks of ours fail with this error, seemingly at random.
Get-AutomationPSCredential is an Azure-provided module. It's not our code, it's Microsoft's.
And sometimes, it appears to just "go away".
So what's happening here? Is the Azure Automation infrastructure reloading or updating modules at an inopportune time for our job? I was under the impression that once a runbook is scheduled, the dependent modules are "bound" to the runbook, so they'll be there when needed.
Why does this happen and what's the best defense against failure?