Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer

$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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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