diff --git a/ChangeLog.md b/ChangeLog.md index 8c38cdefb168..8abcfbc57b6d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,7 @@ ## 2015.09.03 version 0.9.8 - +* Azure Compute (ARM) Cmdlets + * Add -Launch parameter for Get-AzureRemoteDesktopFile cmdlet + ## 2015.08.17 version 0.9.7 * Azure Profile cmdlets * New-AzureProfile diff --git a/src/ResourceManager/Compute/Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs b/src/ResourceManager/Compute/Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs index 258c8c1f7636..046e8f1ccc55 100644 --- a/src/ResourceManager/Compute/Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/RemoteDesktop/GetAzureRemoteDesktopFileCommand.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Management.Automation; @@ -46,15 +47,32 @@ public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseC Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, - HelpMessage = "Path and name of the output RDP file.")] + HelpMessage = "Path and name of the output RDP file.", + ParameterSetName = "Download")] + [Parameter( + Mandatory = false, + Position = 2, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Path and name of the output RDP file.", + ParameterSetName = "Launch")] [ValidateNotNullOrEmpty] - public string LocalPath { get; set;} + public string LocalPath { get; set; } + + [Parameter( + Mandatory = true, + Position = 3, + HelpMessage = "Start a remote desktop session to the specified role instance.", + ParameterSetName = "Launch")] + public SwitchParameter Launch + { + get; + set; + } public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - ExecuteClientAction(() => { const string fullAddressPrefix = "full address:s:"; @@ -138,11 +156,46 @@ public override void ExecuteCmdlet() } // Write to file - using (var file = new StreamWriter(this.LocalPath)) + string rdpFilePath = this.LocalPath ?? Path.GetTempFileName(); + + using (var file = new StreamWriter(rdpFilePath)) { file.WriteLine(fullAddressPrefix + address + ":" + port); file.WriteLine(promptCredentials); } + + if (Launch.IsPresent) + { + var startInfo = new ProcessStartInfo + { + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }; + + if (this.LocalPath == null) + { + string scriptGuid = Guid.NewGuid().ToString(); + + string launchRDPScript = Path.GetTempPath() + scriptGuid + ".bat"; + using (var scriptStream = File.OpenWrite(launchRDPScript)) + { + var writer = new StreamWriter(scriptStream); + writer.WriteLine("start /wait mstsc.exe " + rdpFilePath); + writer.WriteLine("del " + rdpFilePath); + writer.WriteLine("del " + launchRDPScript); + writer.Flush(); + } + + startInfo.FileName = launchRDPScript; + } + else + { + startInfo.FileName = "mstsc.exe"; + startInfo.Arguments = rdpFilePath; + } + + Process.Start(startInfo); + } }); }