Get-AutomationConnection cmdlet not working as expected. It's throwing error while running in Runbook.

Ramakrishna Abhijeet P 70 Reputation points
2023-08-21T08:48:03.0866667+00:00

When I tried to fetch connection values of the Automation account from one of its runbook its failed and threw the below errors.

Using AzureRM Module

$ErrorActionPreference = "Stop"

$vstsConnection = Get-AutomationConnection -Name "vstsConnection"

Write-Output "VstsConnection: $VstsConnection"

Error:

Failed

Unable to cast object of type 'System.Json.JsonPrimitive' to type 'System.Json.JsonObject'. (Unable to cast object of type 'System.Json.JsonPrimitive' to type 'System.Json.JsonObject'.)

 

Using AZ Module

$ErrorActionPreference = "Stop"

$rgname = "RG Name"

$automationaccname = "Automation Account Name"

$vstsConnection = Get-AzAutomationConnection -Name "vstsConnection" -ResourceGroupName $rgname -AutomationAccountName $automationaccname

Write-Output "VstsConnection: $VstsConnection"

Error:

Failed
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Object reference not set to an instance of an object.
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Ramakrishna Abhijeet P 70 Reputation points
    2023-08-23T16:26:41.2833333+00:00

    The West Central US region is one of the early regions where a change is being made to run cloud jobs on Containers instead of Sandbox that automation jobs used to run.

    The role out of this change was gradual, so some jobs run on Sandbox and others on containers. I found that all the jobs that run on a sandbox complete successfully and the ones that run on containers fail. This explains the intermittent failures that you observed.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.