Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Automation/Automation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
49 changes: 42 additions & 7 deletions src/Automation/Automation/Common/PowershellJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,24 +45,58 @@ 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))
{
return null;
}

Hashtable parameters = new Hashtable();
int PSVersion = 5;
Collection<PSObject> 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<PSObject> InvokeScript(string scriptName, Hashtable parameters)
Expand Down