Skip to content

Commit 7bd1100

Browse files
Ab0907BethanyZhou
andauthored
Bug fix: "Get-AzAutomationJob fails for some jobIds" (Azure#19155)
* Update AutomationPSClient.cs * Change summary limit * Update src/Automation/Automation/Common/AutomationPSClient.cs Co-authored-by: Beisi Zhou <zhoubeisi@gmail.com> * Update JobStream.cs * Update Constants.cs * Update ChangeLog.md * Update src/Automation/Automation/Common/AutomationPSClient.cs Co-authored-by: Beisi Zhou <zhoubeisi@gmail.com> * Update AutomationPSClient.cs * Update PowershellJsonConverter.cs * Update ChangeLog.md * Update PowershellJsonConverter.cs * Update PowershellJsonConverter.cs * Update PowershellJsonConverter.cs * Update PowershellJsonConverter.cs * Update PowershellJsonConverter.cs Co-authored-by: Beisi Zhou <zhoubeisi@gmail.com>
1 parent 6f5aead commit 7bd1100

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

src/Automation/Automation/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* Fixed bug: Export-AzAutomationRunbook no longer adds extra '\' to file names [#11101]
2222
* Fixed bug: Get-AzAutomationDscCompilationJobOutput returns complete summaries [#12322]
2323
* Fixed bug: Get-AzAutomationDscNode [#10404]
24+
* Fixed bug: Get-AzAutomationJob fails for some jobIds
25+
2426

2527
## Version *
2628
* Added logic of returning error if insufficient user permissions are there for `GetAgentRegistrationInfo`

src/Automation/Automation/Common/PowershellJsonConverter.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Automation.Properties;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1617
using System;
1718
using System.Collections;
1819
using System.Collections.ObjectModel;
@@ -44,24 +45,58 @@ public static string Serialize(object inputObject)
4445

4546
return result[0].ToString();
4647
}
47-
48-
public static PSObject Deserialize(string json)
48+
public static PSObject Deserialize(string json)
4949
{
5050
if (string.IsNullOrEmpty(json))
5151
{
5252
return null;
5353
}
5454

5555
Hashtable parameters = new Hashtable();
56+
int PSVersion = 5;
57+
Collection<PSObject> result=null;
58+
bool JsonParseStatus = false;
59+
PSVersion = Int32.Parse(AzurePSCmdlet.PowerShellVersion[0].ToString());
5660
parameters.Add(Constants.PsCommandParamInputObject, json);
57-
var result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters);
58-
if (result.Count != 1)
61+
if (PSVersion > 6)
5962
{
60-
return null;
63+
try
64+
{
65+
result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters);
66+
JsonParseStatus = true;
67+
}
68+
catch (Exception)
69+
{
70+
71+
}
72+
if(!JsonParseStatus)
73+
{
74+
return json;
75+
}
76+
else
77+
{
78+
if (result.Count != 1)
79+
{
80+
return null;
81+
}
82+
return result[0];
83+
}
84+
85+
}
86+
else
87+
{
88+
result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters);
89+
90+
91+
if (result.Count != 1)
92+
{
93+
return null;
94+
}
95+
96+
//count == 1. return the first psobject
97+
return result[0];
6198
}
6299

63-
//count == 1. return the first psobject
64-
return result[0];
65100
}
66101

67102
private static Collection<PSObject> InvokeScript(string scriptName, Hashtable parameters)

0 commit comments

Comments
 (0)