How to Programmatically Import Multiple RDP Files into Remote Desktop Connection Manager 2.7 Using PowerShell


2 views

As many sysadmins know, Microsoft Remote Desktop Connection Manager (RDCMan) 2.7 doesn't provide native support for importing settings from standard RDP files. When dealing with hundreds of servers, manual entry becomes impractical. Let me share a solution I've developed through PowerShell scripting.

RDCMan stores connections in an XML-based .rdg file format. Here's a basic structure example:

<?xml version="1.0" encoding="utf-8"?>
<RDCMan schemaVersion="1">
  <file>
    <credentialsProfile inherit="None" />
    <properties>
      <name>ServerGroup</name>
    </properties>
    <server>
      <name>server1.example.com</name>
      <displayName>Production Server 1</displayName>
      <comment />
    </server>
  </file>
</RDCMan>

This script converts multiple RDP files into an RDG file:

# Import RDP files to RDG
$rdpFiles = Get-ChildItem -Path "C:\RDPs\" -Filter *.rdp
$outputFile = "C:\connections.rdg"

$xmlHeader = @"
<?xml version="1.0" encoding="utf-8"?>
<RDCMan schemaVersion="1">
  <file>
    <credentialsProfile inherit="None" />
    <properties>
      <name>Imported Servers</name>
    </properties>
"@

$xmlFooter = @"
  </file>
</RDCMan>
"@

$serverEntries = foreach ($rdp in $rdpFiles) {
    $content = Get-Content $rdp.FullName
    $serverName = ($content | Where-Object { $_ -match "^full address:s:(.+)" })[0] -replace "^full address:s:",""
    $displayName = $rdp.BaseName
    
    @"
    <server>
      <name>$serverName</name>
      <displayName>$displayName</displayName>
    </server>
"@
}

$completeXml = $xmlHeader + ($serverEntries -join "n") + $xmlFooter
$completeXml | Out-File -FilePath $outputFile -Encoding utf8

For more complex RDP parameters, extend the script:

$serverEntry = @"
<server>
  <name>$serverName</name>
  <displayName>$displayName</displayName>
  <comment />
  <logonCredentials inherit="None">
    <userName>$($credParams.UserName)</userName>
    <password>$($credParams.Password)</password>
  </logonCredentials>
  <connectionSettings inherit="None">
    <port>$($connParams.Port)</port>
  </connectionSettings>
</server>
"@

For those preferring GUI solutions:

  • RD Tabs (commercial alternative with import features)
  • mRemoteNG (open-source alternative)
  • Royal TS (enterprise remote desktop management)

Consider these enhancements for production use:

  • Create a FileSystemWatcher to automatically process new RDP files
  • Integrate with Active Directory for credential management
  • Add error handling for malformed RDP files

As an IT professional managing hundreds of remote servers, I frequently receive batches of RDP files from different clients. While Microsoft's Remote Desktop Connection Manager 2.7 (RDCM) is excellent for organizing connections, its native import functionality only handles server names - not the full connection settings stored in RDP files.

Standard RDP files contain key-value pairs that define connection parameters. Here's a snippet from a typical file:

full address:s:192.168.1.100
username:s:admin
authentication level:i:2
redirectprinters:i:1

We can create a PowerShell script to parse RDP files and generate RDCM-compatible XML. First, let's examine the RDCM group file structure (typically .rdg):

<?xml version="1.0"?>
<RDCMan programVersion="2.7" schemaVersion="3">
  <file>
    <properties>
      <name>ServerGroup</name>
    </properties>
    <server>
      <name>Server1</name>
      <connectionSettings>
        <serverName>192.168.1.100</serverName>
        <userName>admin</userName>
      </connectionSettings>
    </server>
  </file>
</RDCMan>

Here's a complete solution to batch convert RDP files to RDCM format:

# Import-RDPtoRDCM.ps1
param(
    [string]$RDPFolder = "C:\RDP_Files",
    [string]$OutputFile = "C:\RDP_Import.rdg"
)

$xmlTemplate = @'
<?xml version="1.0"?>
<RDCMan programVersion="2.7" schemaVersion="3">
  <file>
    <properties>
      <name>Imported_Servers</name>
    </properties>
    {0}
  </file>
</RDCMan>
'@

$serverEntries = New-Object System.Text.StringBuilder

Get-ChildItem -Path $RDPFolder -Filter "*.rdp" | ForEach-Object {
    $content = Get-Content $_.FullName
    $serverName = ($content | Where-Object { $_ -match "^full address:s:" }) -replace "^full address:s:",""
    $userName = ($content | Where-Object { $_ -match "^username:s:" }) -replace "^username:s:",""
    
    $serverEntry = @"
    <server>
      <name>$($_.BaseName)</name>
      <connectionSettings>
        <serverName>$serverName</serverName>
        <userName>$userName</userName>
      </connectionSettings>
    </server>
"@
    
    [void]$serverEntries.AppendLine($serverEntry)
}

$finalXml = $xmlTemplate -f $serverEntries.ToString()
$finalXml | Out-File -FilePath $OutputFile -Encoding UTF8

For enterprise environments, consider these enhancements:

  • Add error handling for malformed RDP files
  • Include additional RDP parameters like gateway settings
  • Implement logging for audit purposes
  • Schedule as a monthly automated task with new RDP batches

If scripting isn't feasible, consider these alternatives:

  • Remote Desktop Manager (Devolutions) - Commercial tool with RDP import
  • mRemoteNG - Open source alternative with better import support
  • Royal TS - Powerful credential management with RDP import