diff --git a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj
index 6392bda88b1f..b43c069a262c 100644
--- a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj
+++ b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj
@@ -168,6 +168,7 @@
+
diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/PowershellJsonConverter.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/PowershellJsonConverter.cs
new file mode 100644
index 000000000000..499de7915f3d
--- /dev/null
+++ b/src/ServiceManagement/Automation/Commands.Automation/Common/PowershellJsonConverter.cs
@@ -0,0 +1,84 @@
+using Microsoft.Azure.Commands.Automation.Properties;
+using System;
+using System.Collections;
+using System.Collections.ObjectModel;
+using System.Globalization;
+using System.Management.Automation;
+using System.Management.Automation.Runspaces;
+using System.Text;
+
+namespace Microsoft.Azure.Commands.Automation.Common
+{
+ public static class PowershellJsonConverter
+ {
+ private const string PsCommandConvertToJson = "ConvertTo-Json";
+ private const string PsCommandConvertFromJson = "ConvertFrom-Json";
+ private const string PsCommandParamInputObject = "InputObject";
+ private const string PsCommandParamDepth = "Depth";
+
+ public static PSObject Deserialize(string json)
+ {
+ if (String.IsNullOrEmpty(json))
+ {
+ return null;
+ }
+
+ Hashtable parameters = new Hashtable();
+ parameters.Add(PsCommandParamInputObject, json);
+ var result = PowershellJsonConverter.InvokeScript(PsCommandConvertFromJson, parameters);
+ if (result.Count != 1)
+ {
+ return null;
+ }
+
+ //count == 1. return the first psobject
+ return result[0];
+ }
+
+ ///
+ /// Invokes a powershell script using the same runspace as the caller.
+ ///
+ /// script name
+ /// parameters for the script
+ ///
+ private static Collection InvokeScript(string scriptName, Hashtable parameters)
+ {
+ using (Pipeline pipe = Runspace.DefaultRunspace.CreateNestedPipeline())
+ {
+ Command scriptCommand = new Command(scriptName);
+
+ foreach (DictionaryEntry parameter in parameters)
+ {
+ CommandParameter commandParm = new CommandParameter(parameter.Key.ToString(), parameter.Value);
+ scriptCommand.Parameters.Add(commandParm);
+ }
+ pipe.Commands.Add(scriptCommand);
+
+ var result = pipe.Invoke();
+
+ //Error handling
+ if (pipe.Error.Count > 0)
+ {
+ StringBuilder errorStringBuilder = new StringBuilder();
+ while (!pipe.Error.EndOfPipeline)
+ {
+ var value = pipe.Error.Read() as PSObject;
+ if (value != null)
+ {
+ var r = value.BaseObject as ErrorRecord;
+ if (r != null)
+ {
+ errorStringBuilder.AppendLine(r.InvocationInfo.MyCommand.Name + " : " + r.Exception.Message);
+ errorStringBuilder.AppendLine(r.InvocationInfo.PositionMessage);
+ }
+ }
+ }
+
+ throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture,
+ Resources.PowershellJsonDecrypterFailed, errorStringBuilder.ToString()));
+ }
+ return result;
+ }
+ }
+ }
+}
diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs
index a2786266b526..a2b4d4a660e7 100644
--- a/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs
+++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs
@@ -12,14 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------
-using System;
using Microsoft.Azure.Commands.Automation.Common;
+using System;
namespace Microsoft.Azure.Commands.Automation.Model
{
using AutomationManagement = Management.Automation;
- using Newtonsoft.Json;
- using System.Management.Automation;
///
/// The Variable.
@@ -48,7 +46,7 @@ public Variable(AutomationManagement.Models.Variable variable, string automation
}
else
{
- this.Value = JsonConvert.DeserializeObject