Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know if is it possible to modify/create values in XML files using PowerShell. Basically I'm interested in:

  • Modify values in the XML file or create them if they don't exist (i.e. I need to search the item, create if not exists and modify the value)
  • Deal with different XML syntax in the same XML file like those ones:

Syntax 1:

  <setting id="Location2" value="Barcelona, Spain"/>
  <setting id="Location2id" value="zmw:00000.1.08181"/>

Syntax 2:


Syntax 3:

        <setting type="bool" name="skin.confluence.HomepageHideRecentlyAddedVideo">false</setting>

Any help would be very appreciated.


share|improve this question

PowerShell fully supports dealing with XML files.

For example, if we take the first blurb you supplied and just paste it into an XML file named settings.xml in folder "C:\blah", you could get the ID of each setting as such:

[xml]$myXML = Get-Content C:\blah\settings.xml

Which returns:





Barcelona, Spain

If we replace the XML file contents with the blurb you provided in Syntax #2:

[xml]$myXML = Get-Content C:\blah\settings.xml



To read crossfade, change it (to 2), and save back:

[xml]$myXML = Get-Content C:\blah\settings.xml
$myXML.settings.musicplayer.crossfade = 2

Edit after comments:

To change the XML elements themselves (as in the Barcelona example) is a little trickier, because you're editing the XML structure itself, not the data it contains.

[xml]$myXML = Get-Content C:\blah\settings.xml
$myXML.settings.ChildNodes.Item(0).value = "New York, USA"

For the Skinsettings example, try something like:

$myXML.settings.skinsettings.setting."#text" = "true"

Check out these resources:

share|improve this answer
Thanks for the answer. I've read your suggestions and I'm trying to update the value of id="Location2" in the first blob from Barcelona to New York without success. The same with the third blob (trying to change to "true"). How can I find/modify these kinds of values? – Serieofilo Mar 9 '13 at 16:57
I'm trying selecting the node I want to change using the following $MyXML.SelectSingleNode("/settings/skinsettings/setting[@type='bool' and @name='skin.confluence.HomepageHideRecentlyAddedVideo']") but, how can I change the value from "false" to "true". Or how can I create a node like this if it doesn't exist? – Serieofilo Mar 9 '13 at 17:32
Check out my edit. I added some more info. :) – Ƭᴇcʜιᴇ007 Mar 9 '13 at 18:49

You must log in to answer this question.

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