Skip to content

Commit 0fe82e9

Browse files
committed
Updated changelog and Resolved the issue where the Verbose streams stop working after calling some Automation cmdlets (for example Get-AzureRmAutomationVariable, Get-AzureRmAutomationJob)
1 parent 9ef9080 commit 0fe82e9

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/ResourceManager/Automation/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21-
21+
* Made changes to AutomationDSC* cmdlets to pull more than 100 records
22+
* Resolved the issue where the Verbose streams stop working after calling some Automation cmdlets (for example Get-AzureRmAutomationVariable, Get-AzureRmAutomationJob).
2223
## Version 3.2.0
2324
* Properly setting TimeZone value for Weekly and Monthly schedules for New-AzureRmAutomationSchedule
2425
- More information can be found in this issue: https://github.com/Azure/azure-powershell/issues/3043

src/ResourceManager/Automation/Commands.Automation/Common/PowershellJsonConverter.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.Collections.ObjectModel;
1919
using System.Globalization;
2020
using System.Management.Automation;
21-
using System.Management.Automation.Runspaces;
2221
using System.Text;
2322

2423
namespace Microsoft.Azure.Commands.Automation.Common
@@ -72,40 +71,31 @@ public static PSObject Deserialize(string json)
7271
/// <returns></returns>
7372
private static Collection<PSObject> InvokeScript(string scriptName, Hashtable parameters)
7473
{
75-
using (Pipeline pipe = Runspace.DefaultRunspace.CreateNestedPipeline())
74+
using (var powerShell = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
7675
{
77-
Command scriptCommand = new Command(scriptName);
78-
76+
powerShell.AddCommand(scriptName);
7977
foreach (DictionaryEntry parameter in parameters)
8078
{
81-
CommandParameter commandParm = new CommandParameter(parameter.Key.ToString(), parameter.Value);
82-
scriptCommand.Parameters.Add(commandParm);
79+
powerShell.AddParameter(parameter.Key.ToString(), parameter.Value);
8380
}
84-
pipe.Commands.Add(scriptCommand);
8581

86-
var result = pipe.Invoke();
82+
83+
var result = powerShell.Invoke();
8784

8885
//Error handling
89-
if (pipe.Error.Count > 0)
86+
if (powerShell.HadErrors)
9087
{
9188
StringBuilder errorStringBuilder = new StringBuilder();
92-
while (!pipe.Error.EndOfPipeline)
89+
foreach (var error in powerShell.Streams.Error)
9390
{
94-
var value = pipe.Error.Read() as PSObject;
95-
if (value != null)
96-
{
97-
var r = value.BaseObject as ErrorRecord;
98-
if (r != null)
99-
{
100-
errorStringBuilder.AppendLine(r.InvocationInfo.MyCommand.Name + " : " + r.Exception.Message);
101-
errorStringBuilder.AppendLine(r.InvocationInfo.PositionMessage);
102-
}
103-
}
91+
errorStringBuilder.AppendLine(error.InvocationInfo.MyCommand.Name + " : " + error.Exception.Message);
92+
errorStringBuilder.AppendLine(error.InvocationInfo.PositionMessage);
10493
}
10594

10695
throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture,
107-
Resources.PowershellJsonDecrypterFailed, errorStringBuilder.ToString()));
96+
Resources.PowershellJsonDecrypterFailed, errorStringBuilder.ToString()));
10897
}
98+
10999
return result;
110100
}
111101
}

0 commit comments

Comments
 (0)