I need to replace the string into a file using PowerShell command.
Inside a file there are XML elements and I need to replace a particular element <version>1.0.0.0</version> with another string <version>3.0.0.0</version>.
For normal string I could write like below:
(Get-Content "D:\data.text").replace('1.0.0', '3.0.0') | Set-Content D:\data.text
How to do expression or pattern which could replace the content between <version></version> element.
EDIT:
Content of file is below:
<?xml version="1.0"?>
<package>
<metadata>
<id>C:\BuildAgent_SpiderWeb\work\52d106957b762949 \buildoutput\LatestPublished</id>
<version>3.0.0</version>
<authors>sonidha-a</authors>
</metadata>
</package>
Need: To replace the content between ID element and Version element.
[xml]$data = Get-Content "D:\Data.Text"; $data.x.y.z.Version = "3.0.0.0"