Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management.Automation;
Expand Down Expand Up @@ -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:";
Expand Down Expand Up @@ -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);
}
});
}

Expand Down