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.