Answer the question
In order to leave comments, you need to log in
How to edit XML in PowerShell?
Greetings!
Faced a problem to edit xml in powershell. It's not tricky, but something is going wrong.
Below is a simplified piece of xml, I need to change the SerialConnectionTimeout parameter.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<applicationSettings>
<Vendor.Some.App.Properties.Settings>
<setting name="TimeoutStep" serializeAs="String">
<value>300</value>
</setting>
<setting name="TimeoutDuration" serializeAs="String">
<value>5000</value>
</setting>
<setting name="SerialConnectionTimeout" serializeAs="String">
<value>1000</value>
</setting>
</Vendor.Some.App.Properties.Settings>
</applicationSettings>
</configuration>
$xml = New-Object -TypeName XML
$file = 'C:\config.xml'
$xml.Load($file)
$xml.configuration.applicationSettings.'Vendor.Some.App.Properties.Settings'.setting.SerialConnectionTimeout
$xml.configuration.applicationSettings.'Vendor.Some.App.Properties.Settings'.setting.name `
| where {$_.name -eq "SerialConnectionTimeout"} | select -ExpandProperty value
Answer the question
In order to leave comments, you need to log in
did you try that?
$node = $xml.configuration.applicationSettings.'Vendor.Some.App.Properties.Settings'.setting `
| where {$_.name -eq "SerialConnectionTimeout"}
$node.Value = "yourvalue"
...
$xml.Save($file)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question