0

I read for hours trying to figure this out, but I'm new to XML.

I am trying to add the following:

<componentInfo osType="Windows" consumeLicense="1" clientSidePackage="1" ComponentName="File System" ComponentId="702"/>

I am trying to add this in <components>

This is what I have before the componenets tag:

-<CVInstallManager_ClientSetup Operationtype="0" OEMID="1" JobID="0" Focus="Instance001">-<CommServeInfo><CommserveHostInfo hostName="$Var2"/></CommServeInfo>-<clientComposition packageDeliveryOption="0" activateClient="1">-<clientInfo>-<client installDirectory="" evmgrcPort="8402" cvdPort="8400"><clientEntity hostName="$VAr1" clientName="$Var3"/><jobResulsDir path=""/></client><clientGroups clientGroupName=""/><clientProps enableAccessControl="0"/></clientInfo>

I've got the XML loaded like the following:

$InstallXML = [xml] (Get-Content "C:\somedir\dir\InstallXMLTest.xml")

I understand I need to browse to the tag, similar to:

$InstallXML.CVInstallManager_ClientSetup.CommServeInfo.CommserveHostInfo.hostName = $args[1]

But I have no idea how I add, not replace data. Please save me!

Mike
  • 207
  • 1
  • 4
  • 16
  • I have no idea whats going on in that thread.. I need to add attributes to an element that is already present, That thread looks like an in - depth discussion. I'm looking for explanation really, – Mike Dec 15 '15 at 09:16
  • Hi Mike, does the example in the first answer of this question help you ? http://stackoverflow.com/q/3041489/3677139 – sodawillow Dec 15 '15 at 10:04
  • The accepted answer shows (rather simple and straightforward) how to add an attribute to a node and how to append that node to another node. It contains everything you need for solving your problem. Other answers can be found by searching this site. Please do some legwork yourself. We're not here for spoon-feeding you a solution. – Ansgar Wiechers Dec 15 '15 at 11:42
  • I've figured it out.. http://stackoverflow.com/questions/3041489/powershell-how-to-add-xmlelement-to-a-non-root-element Basically you create the element and assign attributes, you then move that to what ever tag/element you want to. This is what threw me off. By no means do I want to be spoon fed, but I've been trying this for several days and not made much progress. I used the following to do what I want: `code` $b = $InstallXML.CreateElement("componentInfo") $b.SetAttribute('ComponentId', '705') $InstallXML.CVInstallManager_ClientSetup.clientComposition.components.AppendChild($b) `code` – Mike Dec 15 '15 at 14:28

0 Answers0