Read and Write/Update the XML file in Powershell

In many cases, we found ourselves in a situation where we need to Read and update XML files.

It’s quite straight forward in Power Shell.

Sample XML File: 

Powershell script to read and update XML file

<App>
<Secret></Secret>
</App>
view raw sample.xml hosted with ❤ by GitHub

Powershell script to read and write XML file

$xmlFileName "Path to XML File";
[xml]$xmlDoc = Get-Content $xmlFileName
$xmlDoc.APP.Secret = "Some Value"
$xmlDoc.Save($xmlFileName)
view raw read-write-xml.ps1 hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s