Create Azure Cloud Service Remote Desktop Connection Manager File (.rdg)

Last week I launched an RDP session to an Azure VM with the aid of a PowerShell cmdlet. For me, this is much easier than finding the required RDP link in one of the the Azure portals and I've been using the PowerShell method for a while.

Now, in writing last week's post I thought to myself, "How could I make my Azure life even easier?" The answer flows below...

  

Remote Desktop Connection Manager

Wouldn't it be good if there was an application that could store and group all of your remote desktop connections? Well, strangely enough, there is one and it's been available for a long time!

Remote Desktop Connection Manager 2.7

 

The application uses .rdg files to store information about a group of remote desktop connections.

Wouldn't it be even better if there was a PowerShell function that could create these .rdg files for you? And, wouldn't it be even, even better if that same function could target an Azure cloud service and create a .rdg file for all of the Windows VMs in that cloud service?

You know where this is going, my friend!

 

Create-AzureServiceRdgFile

And, here it is... a function for creating a .rdg file for a targeted cloud service.

Create Azure Cloud Service Remote Desktop Connection Manager Group File (.rdg)

 

Here's how you use it:

  1. Make sure you have the most up to date Azure PowerShell module
  2. Run the function, supplying a target cloud service and a directory in which to store the resultant rdg file
    1. For example: Create-AzureServiceRdgFile -ServiceName FredCLoud -FolderPath "c:\users\fred\rdg_files\" -Verbose
  3. Start the Remote Desktop Connection Manager
  4. Click File / Open and navigate to the folder containing the rdg file
  5. Select the rdg file and fire up some remote connections!

 

Why is all this possible? Man, that's an ontological question! Let's just stick to the rdg file - it's XML, so we take an XML template and populate it with information gathered from our Azure service.

The initial XML template contains the group / cloud service information stored in the 'properties' node:

[XML]$RdgFile = @"

<?xml version="1.0" encoding="utf-8"?>

<RDCMan schemaVersion="1">

<version>2.2</version>

<file>

<properties>

<name>Azure - $ServiceName</name>

<expanded>True</expanded>

<comment>RDP connections for Azure cloud service - $ServiceName</comment>

<logonCredentials inherit="FromParent" />

<connectionSettings inherit="FromParent" />

<gatewaySettings inherit="FromParent" />

<remoteDesktop inherit="FromParent" />

<localResources inherit="FromParent" />

<securitySettings inherit="FromParent" />

<displaySettings inherit="FromParent" />

</properties>

</file>

</RDCMan>

"@

 

Each server is then added to a new 'server' node and appended to the original XML document as part of a foreach loop.

[XML]$ServerNode = @"

<server>

<name>$ServiceFqdn</name>

<displayName>$(($VM).InstanceName)</displayName>

<comment>RDP configuration for $(($VM).InstanceName)</comment>

<logonCredentials inherit="FromParent" />

<connectionSettings inherit="None">

<connectToConsole>True</connectToConsole>

<startProgram />

<workingDir />

<port>$VmPort</port>

</connectionSettings>

<gatewaySettings inherit="FromParent" />

<remoteDesktop inherit="FromParent" />

<localResources inherit="FromParent" />

<securitySettings inherit="FromParent" />

<displaySettings inherit="FromParent" />

</server>

"@

#Create an import template for the server node

$ImportNode = $RdgFile.ImportNode($ServerNode.Server,$true)

#Append the template to our existing XML document

$RdgFile.RDCMan.File.AppendChild($ImportNode) | Out-Null

  

For each VM in the cloud service the variables in the XML template are populated with the aid of the following cmdlets:

Get-AzureVM

Get-AzureEndpoint

 

This simple variable substitution, with the loop, gives us our tailored XML document ultimately saved as <cloud_service_name>.rdg.

Finally, here's how to create an rdg file for all of your Azure cloud services:

Get-AzureService | ForEach-Object {

Create-AzureServiceRdgFile -ServiceName $_.ServiceName -FolderPath "c:\users\fred\rdg_files\" -Verbose

}