Skip to content

Commit 36e51bb

Browse files
committed
Fix RunCommand cmdlet
1 parent c85c210 commit 36e51bb

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineRunCommandTests.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,9 @@ function Test-VirtualMachineSetRunCommand
103103

104104
$param = @{"first" = "var1";"second" = "var2"};
105105

106-
#$path = 'F:\hylee-ps\run\src\ResourceManager\Compute\Commands.Compute.Test\bin\Debug\ScenarioTests\test.ps1'
107106
$path = 'ScenarioTests\test.ps1';
108107

109-
$result = Invoke-AzureRmVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId $commandId;
110-
#$result = Invoke-AzureRmVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId $commandId -ScriptPath $path -Parameter $param;
111-
#$vm | Invoke-AzureRmVMRunCommand -CommandId $commandId -ScriptPath $path -Parameter $param;
108+
$result = Invoke-AzureRmVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId $commandId -ScriptPath $path -Parameter $param;
112109
$result_output = $result | Out-String;
113110

114111
# Remove All VMs

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachine/VirtualMachineRunCommandMethod.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,8 @@ protected override void ProcessRecord()
132132
parameters.Script = new List<string>();
133133
PathIntrinsics currentPath = SessionState.Path;
134134
var filePath = new System.IO.FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(this.ScriptPath.ToString()));
135-
string line;
136-
var file = new System.IO.StreamReader(filePath.FullName);
137-
while ((line = file.ReadLine()) != null)
138-
{
139-
parameters.Script.Add(line);
140-
}
135+
string fileContent = WindowsAzure.Commands.Common.FileUtilities.DataStore.ReadFileAsText(filePath.FullName);
136+
parameters.Script = fileContent.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
141137
}
142138
if (this.Parameter != null)
143139
{
@@ -192,7 +188,7 @@ protected override void ProcessRecord()
192188
[Parameter(
193189
Mandatory = false)]
194190
[AllowNull]
195-
public System.IO.FileInfo ScriptPath { get; set; }
191+
public string ScriptPath { get; set; }
196192

197193
[Parameter(
198194
Mandatory = false)]

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineRunCommand/VirtualMachineRunCommandGetMethod.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Changes to this file may cause incorrect behavior and will be lost if the
2020
// code is regenerated.
2121

22+
using AutoMapper;
2223
using Microsoft.Azure.Commands.Compute.Automation.Models;
2324
using Microsoft.Azure.Management.Compute;
2425
using Microsoft.Azure.Management.Compute.Models;
@@ -118,11 +119,12 @@ protected PSArgument[] CreateVirtualMachineRunCommandGetParameters()
118119
}
119120

120121
[Cmdlet(VerbsCommon.Get, "AzureRmVMRunCommandDocument", DefaultParameterSetName = "DefaultParameter")]
121-
[OutputType(typeof(RunCommandDocument))]
122+
[OutputType(typeof(PSRunCommandDocument))]
122123
public partial class GetAzureRmVMRunCommandDocument : ComputeAutomationBaseCmdlet
123124
{
124125
protected override void ProcessRecord()
125126
{
127+
AutoMapper.Mapper.AddProfile<ComputeAutomationAutoMapperProfile>();
126128
ExecuteClientAction(() =>
127129
{
128130
string location = this.Location;
@@ -131,7 +133,9 @@ protected override void ProcessRecord()
131133
if (!string.IsNullOrEmpty(location) && !string.IsNullOrEmpty(commandId))
132134
{
133135
var result = VirtualMachineRunCommandsClient.Get(location, commandId);
134-
WriteObject(result);
136+
var psObject = new PSRunCommandDocument();
137+
Mapper.Map<RunCommandDocument, PSRunCommandDocument>(result, psObject);
138+
WriteObject(psObject);
135139
}
136140
else if (!string.IsNullOrEmpty(location))
137141
{
@@ -147,7 +151,12 @@ protected override void ProcessRecord()
147151
}
148152
nextPageLink = pageResult.NextPageLink;
149153
}
150-
WriteObject(resultList, true);
154+
var psObject = new List<PSRunCommandDocumentBase>();
155+
foreach (var r in resultList)
156+
{
157+
psObject.Add(Mapper.Map<RunCommandDocumentBase, PSRunCommandDocumentBase>(r));
158+
}
159+
WriteObject(psObject, true);
151160
}
152161
});
153162
}

0 commit comments

Comments
 (0)