I am trying to use powershell to update xml nodes in my web.config.
If the configuration element looks like below with xmlns it does not work
configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
If I remove the xmlns attribute, then it works fine. I would rather not have to remove that attribute from all of our web.config files.
I want to be able to pass in parameters to the Powershell script, so I wrote it this way.
Param($config_path,$node,$new_value)
# Get the content of the config file and cast it to XML
$xml = [xml](get-content $config_path)
#get node and set the new value for configSource
#//client[@configSource] sample node
$xml.SelectSingleNode("$node").configSource = $new_value
# Save it
$xml.Save($config_path)
Is there any possible way I can use Powershell to do the same thing without having to remove the xmlns attribute. Here's an article about why SelectSingleNode does not work with xmlns, but I do not know how I can do what I need with Powershell.
http://devio.wordpress.com/2008/07/22/xmlns-selectnodes-empty-xmlnodelist/