Description

This is an update on the earlier version of this script.

I added the ability to add groups.

Then you can add computers to the specific groups.

You cannot nest with this version of the script, so you must specify the parent group when adding the computers.

You can choose to save the config file to a new filename by specifying $NewTemplate or it will overwrite the current config file. Noting that the config file is backed up to the current directory each time the script is run.

Usage:

add-RDCManConfigv2 -GroupName Servers

Usage2:

Get-Content -Path C:\PS\DailyScripts\desktops.txt | Add-RDCManConfigv2 -Parent Servers

Disclaimer:

* Note that I created the default config file with RDCMan first and then use that as the template.

* You must create the parent group first before adding computername's since you must specify the parent parameter.

* Each time you run this the old RDCMan file is backed up in the same directory.

* Use this script at your own risk, I recommend using a new config file, don't mess with one you already have configured.

* As specified in the first version of this script I use it mainly for a specific task, however by allowing groups to be added this should add flexibility into the usage of this script.

* I was thinking about nesting Groups, however didn't add this functionality at this time, so if you try to nest it will report that you cannot do so.

Update:

I now wrote version 2 of this script, the new version also deals with groups.

http://gallery.technet.microsoft.com/scriptcenter/f6550a1d-6ca7-4cc4-b066-a0ea5761866d

Update2:

I now wrote a version 3, that populates the RDCMan file from an Azure resource group.

https://gallery.technet.microsoft.com/Build-an-RDCMan-Remote-406ad27d   

 

Script

PowerShell
Edit|Remove
function global:Add-RDCManConfigv2 { 
 
#Requires -Version 2.0 
[CmdletBinding(DefaultParameterSetName="AddComputers")] 
 Param  
   ( 
    [Parameter(Mandatory=$true, 
               Position=0, 
               ValueFromPipeline=$true, 
               ParameterSetName="AddComputers", 
               ValueFromPipelineByPropertyName=$true)] 
    [String[]]$ComputerName, 
    [Parameter(Mandatory=$true, 
               Position=0, 
               ParameterSetName="Query")] 
    [Switch]$Query, 
    [Parameter(Mandatory=$true, 
               Position=0, 
               ValueFromPipeline=$false, 
               ParameterSetName="AddGroup")] 
    [String]$GroupName, 
    [String]$Parent, 
    [String]$Template = "C:\ps\XML\rdcmantest.rdg", 
    [String]$NewTemplate 
   )#End Param  
 
Begin 
{ 
 Write-Verbose "Adding computers to RDCManConfig . . ." 
 [XML]$RDCConfig = Get-Content -Path $Template 
 # Backup template file 
 Copy-Item -Path $Template -Destination ($Template -replace '.rdg',("{0:_yyyy-MM-dd_hhmm}.rdg" -f (get-date))) 
} 
Process 
{ 
    if ($GroupName) 
        { 
            [XML]$Group ="     
            <group> 
                <properties> 
                    <name>$GroupName</name> 
                    <expanded>True</expanded> 
                    <comment /> 
                    <logonCredentials inherit='FromParent' /> 
                    <connectionSettings inherit='FromParent' /> 
                    <gatewaySettings inherit='FromParent' /> 
                    <remoteDesktop inherit='FromParent' /> 
                    <localResources inherit='FromParent' /> 
                    <securitySettings inherit='FromParent' /> 
                    <displaySettings inherit='FromParent' /> 
                </properties> 
            </group>" 
             
            $NewItem = $RDCConfig.ImportNode($Group.Group$true) 
        }#If(GroupName)                 
    elseif ($ComputerName) 
        { 
            $ComputerName | ForEach-Object { 
            $Computer = $_ 
            [XML]$Server =" 
            <server> 
                <name>$Computer</name> 
                <displayName>$Computer</displayName> 
                <comment /> 
                <logonCredentials inherit='FromParent' /> 
                <connectionSettings inherit='FromParent' /> 
                <gatewaySettings inherit='FromParent' /> 
                <remoteDesktop inherit='FromParent' /> 
                <localResources inherit='FromParent' /> 
                <securitySettings inherit='FromParent' /> 
                <displaySettings inherit='FromParent' /> 
            </server>" 
 
            $NewItem = $RDCConfig.ImportNode($Server.Server, $true) 
            }#Foreach-Object(ComputerName) 
        }#if(ComputerName) 
         
    if ($Parent) 
        { 
            If ($RDCConfig.RDCMan.file.group | where-Object {$_.Properties.Name -eq $Parent}) 
                { 
                    if ($NewItem.properties) 
                        { 
                            'Parent found' | Out-Host 
                            'Cannot nest Groups as yet'  | Out-Host 
                        } 
                    else 
                        { 
                            'Parent found' | Out-Host 
                            $RDCConfig.RDCMan.file.group |  
                            where-Object {$_.Properties.Name -eq $Parent|  
                            Foreach-Object {$_.AppendChild($NewItem)} 
                        } 
                } 
            elseif ($RDCConfig.RDCMan.file.group | ForEach-Object {$_.group| Where-Object {$_.properties.name -eq $Parent}) 
                { 
                    'Parent found nested' | Out-Host 
                    'Cannot nest as yet'  | Out-Host 
                    <# 
                    $RDCConfig.RDCMan.file.group |  
                    ForEach-Object {$_.group} |  
                    Where-Object {$_.properties.name -eq $Parent} 
                    Foreach-Object {$_.AppendChild($NewItem)} 
                    #> 
                } 
            elseif ($RDCConfig.RDCMan.file.group | ForEach-Object {$_.group| ForEach-Object {$_.group| Where-Object {$_.properties.name -eq $Parent}) 
                { 
                    'Parent found nested * 2' | Out-Host 
                    'Cannot nest as yet'  | Out-Host 
                    <#                     
                    $Parent = $RDCConfig.RDCMan.file.group |  
                    ForEach-Object {$_.group} |  
                    ForEach-Object {$_.group} |  
                    Where-Object {$_.properties.name -eq $Parent} | 
                    Foreach-Object {$_.AppendChild($NewItem)} 
                    #> 
                } 
            else 
                { 
                    'No Parent found' | Out-Host 
                    if ($NewItem.properties) 
                        { 
                            'Adding Group' | Out-Host 
                            $RDCConfig.RDCMan.file.AppendChild($NewItem)         
                        } 
                    else 
                        { 
                            try 
                                { 
                                    $RDCConfig.RDCMan.file.group.AppendChild($NewComputer) 
                                } 
                            catch 
                                { 
                                    'You must specify a parent' 
                                } 
                        }                     
                     
                } 
        }#If(Parent)         
    else 
        { 
            'No Parent specified' | Out-Host 
            if ($NewItem.properties) 
                { 
                    'Adding Group' | Out-Host 
                    $RDCConfig.RDCMan.file.AppendChild($NewItem)         
                } 
            else 
                { 
                    try 
                        { 
                            $RDCConfig.RDCMan.file.group.AppendChild($NewComputer) 
                        } 
                    catch 
                        { 
                            'You must specify a parent' 
                        } 
                } 
        } 
} 
End 
{ 
    if ($NewTemplate) 
        { 
            $RDCConfig.Save($NewTemplate) 
        } 
    else  
        { 
            $RDCConfig.Save($Template) 
        } 
} 
 
}#Add-RDCManConfigv2