Ex :
Test
How can I change the value of the node Test to Power
Poweshell script I use:
$configuration = "app.config"
[xml]$xml = New-Object XML $xml.Load($configuration)
$xml.selectnodes("/configuration/Test") = {"UST"}
$xml.Save($configuration)
Ex :
Test
How can I change the value of the node Test to Power
Poweshell script I use:
$configuration = "app.config"
[xml]$xml = New-Object XML $xml.Load($configuration)
$xml.selectnodes("/configuration/Test") = {"UST"}
$xml.Save($configuration)
I don't know what exactly you want to achieve, but the example should give you and idea:
$file = 'c:\temp\aa\ServerService.exe.config'
$x = [xml] (Get-Content $file)
Select-Xml -xml $x -XPath //root/level |
% { $_.Node.'#text' = 'test'
$_.Node.SomeAttribute = 'value'
}
$x.Save($file)
You don't need to use .NET for xpath queries. Just stay with PowerShell (with Select-Xml).
It is also common to load xml file via Get-Content and cast it to [xml] which creates XmlDocument and loads the file content.