Skip to content

Commit 7da0852

Browse files
committed
Merge pull request #806 from DeepakRajendranMsft/AddLaunchOptionOnRDP
Add Launch option to Get-RDP command
2 parents d7af629 + 75b542c commit 7da0852

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 2015.09.03 version 0.9.8
2-
2+
* Azure Compute (ARM) Cmdlets
3+
* Add -Launch parameter for Get-AzureRemoteDesktopFile cmdlet
4+
35
## 2015.08.17 version 0.9.7
46
* Azure Profile cmdlets
57
* New-AzureProfile

src/ResourceManager/Compute/Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs

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

1515
using System;
16+
using System.Diagnostics;
1617
using System.IO;
1718
using System.Linq;
1819
using System.Management.Automation;
@@ -46,15 +47,32 @@ public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseC
4647
Mandatory = true,
4748
Position = 2,
4849
ValueFromPipelineByPropertyName = true,
49-
HelpMessage = "Path and name of the output RDP file.")]
50+
HelpMessage = "Path and name of the output RDP file.",
51+
ParameterSetName = "Download")]
52+
[Parameter(
53+
Mandatory = false,
54+
Position = 2,
55+
ValueFromPipelineByPropertyName = true,
56+
HelpMessage = "Path and name of the output RDP file.",
57+
ParameterSetName = "Launch")]
5058
[ValidateNotNullOrEmpty]
51-
public string LocalPath { get; set;}
59+
public string LocalPath { get; set; }
60+
61+
[Parameter(
62+
Mandatory = true,
63+
Position = 3,
64+
HelpMessage = "Start a remote desktop session to the specified role instance.",
65+
ParameterSetName = "Launch")]
66+
public SwitchParameter Launch
67+
{
68+
get;
69+
set;
70+
}
5271

5372
public override void ExecuteCmdlet()
5473
{
5574
base.ExecuteCmdlet();
5675

57-
5876
ExecuteClientAction(() =>
5977
{
6078
const string fullAddressPrefix = "full address:s:";
@@ -138,11 +156,46 @@ public override void ExecuteCmdlet()
138156
}
139157

140158
// Write to file
141-
using (var file = new StreamWriter(this.LocalPath))
159+
string rdpFilePath = this.LocalPath ?? Path.GetTempFileName();
160+
161+
using (var file = new StreamWriter(rdpFilePath))
142162
{
143163
file.WriteLine(fullAddressPrefix + address + ":" + port);
144164
file.WriteLine(promptCredentials);
145165
}
166+
167+
if (Launch.IsPresent)
168+
{
169+
var startInfo = new ProcessStartInfo
170+
{
171+
CreateNoWindow = true,
172+
WindowStyle = ProcessWindowStyle.Hidden
173+
};
174+
175+
if (this.LocalPath == null)
176+
{
177+
string scriptGuid = Guid.NewGuid().ToString();
178+
179+
string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat";
180+
using (var scriptStream = File.OpenWrite(launchRDPScript))
181+
{
182+
var writer = new StreamWriter(scriptStream);
183+
writer.WriteLine("start /wait mstsc.exe " + rdpFilePath);
184+
writer.WriteLine("del " + rdpFilePath);
185+
writer.WriteLine("del " + launchRDPScript);
186+
writer.Flush();
187+
}
188+
189+
startInfo.FileName = launchRDPScript;
190+
}
191+
else
192+
{
193+
startInfo.FileName = "mstsc.exe";
194+
startInfo.Arguments = rdpFilePath;
195+
}
196+
197+
Process.Start(startInfo);
198+
}
146199
});
147200
}
148201

0 commit comments

Comments
 (0)