diff --git a/src/Automation/Automation/ChangeLog.md b/src/Automation/Automation/ChangeLog.md index aeeaf6c00b1d..d86ac47c873b 100644 --- a/src/Automation/Automation/ChangeLog.md +++ b/src/Automation/Automation/ChangeLog.md @@ -21,6 +21,8 @@ * Fixed bug: Export-AzAutomationRunbook no longer adds extra '\' to file names [#11101] * Fixed bug: Get-AzAutomationDscCompilationJobOutput returns complete summaries [#12322] * Fixed bug: Get-AzAutomationDscNode [#10404] +* Fixed bug: Get-AzAutomationJob fails for some jobIds + ## Version * * Added logic of returning error if insufficient user permissions are there for `GetAgentRegistrationInfo` diff --git a/src/Automation/Automation/Common/PowershellJsonConverter.cs b/src/Automation/Automation/Common/PowershellJsonConverter.cs index a43f02527c8a..3e9e71839ca3 100644 --- a/src/Automation/Automation/Common/PowershellJsonConverter.cs +++ b/src/Automation/Automation/Common/PowershellJsonConverter.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.Automation.Properties; +using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; using System.Collections; using System.Collections.ObjectModel; @@ -44,8 +45,7 @@ public static string Serialize(object inputObject) return result[0].ToString(); } - - public static PSObject Deserialize(string json) + public static PSObject Deserialize(string json) { if (string.IsNullOrEmpty(json)) { @@ -53,15 +53,50 @@ public static PSObject Deserialize(string json) } Hashtable parameters = new Hashtable(); + int PSVersion = 5; + Collection result=null; + bool JsonParseStatus = false; + PSVersion = Int32.Parse(AzurePSCmdlet.PowerShellVersion[0].ToString()); parameters.Add(Constants.PsCommandParamInputObject, json); - var result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters); - if (result.Count != 1) + if (PSVersion > 6) { - return null; + try + { + result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters); + JsonParseStatus = true; + } + catch (Exception) + { + + } + if(!JsonParseStatus) + { + return json; + } + else + { + if (result.Count != 1) + { + return null; + } + return result[0]; + } + + } + else + { + result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters); + + + if (result.Count != 1) + { + return null; + } + + //count == 1. return the first psobject + return result[0]; } - //count == 1. return the first psobject - return result[0]; } private static Collection InvokeScript(string scriptName, Hashtable parameters)