param
RdgToWacCsv -RDGfilepath "rdcmangroup.rdg"
#>
function RdgToWacCsv {
param(
[Parameter(Mandatory = $true)]
[String]
$RDGfilepath,
[Parameter(Mandatory = $false)]
[String]
$CSVdirectory
)
[xml]$RDGfile = Get-Content -Path $RDGfilepath
$node = $RDGfile.RDCMan.file
if (!$CSVdirectory){
$csvPath = [System.IO.Path]::GetDirectoryName($RDGfilepath) + [System.IO.Path]::GetFileNameWithoutExtension($RDGfilepath) + "_WAC.csv"
} else {
$csvPath = $CSVdirectory + [System.IO.Path]::GetFileNameWithoutExtension($RDGfilepath) + "_WAC.csv"
}
New-item -Path $csvPath
Add-Content -Path $csvPath -Value '"name","type","tags"'
AddServers -node $node -csvPath $csvPath
Write-Host "Converted $RDGfilepath `nOutput: $csvPath"
}
">#Helper function for RdgToWacCsv
function AddServers {
param (
[Parameter(Mandatory = $true)]
[Xml.XmlLinkedNode]
$node,
[Parameter()]
[String[]]
$tags,
[Parameter(Mandatory = $true)]
[String]
$csvPath
)
if ($node.LocalName -eq 'server') {
$serverName = $node.properties.name
$tagString = $tags -join "|"
Add-Content -Path $csvPath -Value ('"'+ $serverName + '","msft.sme.connection-type.server","'+ $tagString +'"')
}
elseif ($node.LocalName -eq 'group' -or $node.LocalName -eq 'file') {
$groupName = $node.properties.name
$tags+=$groupName
$currNode = $node.properties.NextSibling
while ($currNode) {
AddServers -node $currNode -tags $tags -csvPath $csvPath
$currNode = $currNode.NextSibling
}
}
else {
# Node type isn't relevant to tagging or adding connections in WAC
}
return
}
<#
.SYNOPSIS
Convert an .rdg file from Remote Desktop Connection Manager into a .csv that can be imported into Windows Admin Center, maintaining groups via server tags. This will not modify the existing .rdg file and will create a new .csv file
.DESCRIPTION
This converts an .rdg file into a .csv that can be imported into Windows Admin Center.
.PARAMETER RDGfilepath
The path of the .rdg file to be converted. This file will not be modified, only read.
.PARAMETER CSVdirectory
Optional. The directory you wish to export the new .csv file. If not provided, the new file is created in the same directory as the .rdg file.
.EXAMPLE
C:\PS> RdgToWacCsv -RDGfilepath "rdcmangroup.rdg"
#>
function RdgToWacCsv {
param(
[Parameter(Mandatory = $true)]
[String]
$RDGfilepath,
[Parameter(Mandatory = $false)]
[String]
$CSVdirectory
)
[xml]$RDGfile = Get-Content -Path $RDGfilepath
$node = $RDGfile.RDCMan.file
if (!$CSVdirectory){
$csvPath = [System.IO.Path]::GetDirectoryName($RDGfilepath) + [System.IO.Path]::GetFileNameWithoutExtension($RDGfilepath) + "_WAC.csv"
} else {
$csvPath = $CSVdirectory + [System.IO.Path]::GetFileNameWithoutExtension($RDGfilepath) + "_WAC.csv"
}
New-item -Path $csvPath
Add-Content -Path $csvPath -Value '"name","type","tags"'
AddServers -node $node -csvPath $csvPath
Write-Host "Converted $RDGfilepath `nOutput: $csvPath"
}