Hi,
can u post a little example xml?
There are many possible ways to do this - regex - using xml functions by loading the file as [xml] etc.
You cannot add lines to an XML file. YOU can only add elements and attributes and text nodes. (comments too)
Would editing the file as a text file work or would it mess up the xml format of the file? I can add the line if I edit the file as a text file.
$Filename = 'C:\myfile.xml' (Get-Content $fileName) | Foreach-Object { $_ if ($_ -match "myvalue1234") { "Mynewvalue5678" } } | Set-Content $fileName
Herfore you could also use replace.
$Filename = 'C:\myfile.xml' (Get-Content $fileName).Replace("myvalue1234","Mynewvalue5678") | Set-Content $fileNameIf you dont make any errors to the xml-structure you can modify the file as you like. Though if you make any errors the xml-file wont be read accurately.
Would editing the file as a text file work or would it mess up the xml format of the file? I can add the line if I edit the file as a text file.
$Filename = 'C:\myfile.xml' (Get-Content $fileName) | Foreach-Object { $_ if ($_ -match "myvalue1234") { "Mynewvalue5678" } } | Set-Content $fileName
"match" will replace everything on a line and many XML files are only one line with only a CR.