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.

     C:\sy32\java.exe -jar "C:\Prog\Laun.jar" YAHOO.COM --type SPNG --port 80
       C:\sy32\java.exe -jar "C:\Prog\Laun.jar" YAHOO.COM --type JET --port 80

1 Answer 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.