Avatar of ivan rosa
ivan rosaFlag for United States of America

asked on 

RDG - XML. Configuration settings

Hello Folks, (For the sake of the purpose I reduce the actual code in the XML just to enough for the core of the script to run)

I have this ServersList.csv
displayNamename
VirtualPC1192.168.1.10
VirtualPC2192.168.1.11

In which I intend to replace the properties (displayName, Name) within the this Servers.rdg file. which basically is a XML file:
<?xml version="1.0" encoding="utf-8"?>
<RDCMan programVersion="2.7" schemaVersion="3">
  <file>
    <credentialsProfiles />
    <properties>
      <expanded>True</expanded>
      <name>NorthServers</name>
    </properties>
    <group>
      <server>
        <properties>
          <displayName>VirtualPC</displayName>
          <name>10.10.10.15</name>
        </properties>
      </server>
      <server>
        <properties>
          <displayName>VirtualMachine</displayName>
          <name>10.20.90.7</name>
        </properties>
      </server>
    </group>
  </file>
  <connected />
  <favorites />
  <recentlyUsed />
</RDCMan>

Open in new window

I have attempted todo so like by creating this PowerShell Script:
$vms = Import-Csv -LiteralPath "C:\Temp\ServersList.csv"
[xml]$Template  = Get-Content -Path 'C:\Temp\ServersQ.rdg'
$servers = $Template.RDCMan.file.group.server.properties 

$Template.RDCMan.file.group.server.properties = $vms

Open in new window

Which throws me an error: "The property 'properties' cannot be found on this object. Verify that the property exists and can be set."

is this not the way to manage an XML file, do I need something like a 2D array? what is the best practice ?

Any Advise?


Thanks for looking
Ivan Rosa
PowershellXMLServer Software

Avatar of undefined
Last Comment
Coralon
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

this is for RDMAN (remote desktop manager) I use devolutions remote desktop manager (free)
https://devolutions.net/solutions/remote-connection-management
ASKER CERTIFIED SOLUTION
Avatar of Coralon
Coralon
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ivan rosa
ivan rosa
Flag of United States of America image

ASKER

Thank you Coralon, Although your script worked it actually added more properties to the file as opposed replace the values.
but with that said though, it was good enough for me to see how the manipulation is done, so I added a little more to it
and  ended up with:
$VMList = $null
$xml    = $null 

$VMList  = Import-Csv -Path C:\temp\SERVERSLIST.csv

$xml = [xml]::new()
$xml.Load('C:\temp\ServersQ.rdg')

$index = 0
$nodes = $xml.RDCMan.file.group.server.properties
foreach ($node in  $nodes){
    $node.displayName = $VMList[$index].displayName
    $node.name        = $VMList[$index].name
    $index++
}

$xml.save('c:\temp\servers.rdg')  

Open in new window

Avatar of Coralon
Coralon
Flag of United States of America image

Nice :-)  I wasn't sure if you were using them as templates or not. :-)  


Coralon
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo