2

Please help me create a Powershell script that will go through an XML file and update content. In the example below, I want to use the script to pull out and change the file path in the Config.button.command example. Change C:\Prog\Laun.jar to C:\Prog32\folder\test.jar.

<config>
 <button>
  <name>Spring</name>
  <command>
     C:\sy32\java.exe -jar "C:\Prog\Laun.jar" YAHOO.COM --type SPNG --port 80
  </command>
  <desc>studies</desc>
 </button>
 <button>
  <name>JET</name>
    <command>
       C:\sy32\java.exe -jar "C:\Prog\Laun.jar" YAHOO.COM --type JET --port 80
    </command>
  <desc>school</desc>
 </button>
</config>

1 Answer 1

1
$configFile = 'test.xml'

$xml = [xml](Get-Content -Path $configFile -Encoding Ascii)

foreach($button in $xml.SelectNodes('/config/button')) {

    $button.command = $button.command.Replace('C:\Prog\Laun.jar', 'C:\Prog32\folder\test.jar')
}

$xml.InnerXml | Out-File -FilePath $configFile -Encoding ascii

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .