Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell: Add a linebreak in the find and replace strings

$
0
0

I want to add data to a xml export file. Therefor I need to search for a multiple occurrences of the value with has a linebreak (otherwise the string is not unique for the value I want to change) and replace the value with another linebreak.

There are multiple files in the directory with a filename which contains the date and time on which the file was generated.

The code does work on values without linebreak. I tried with the 'n as linebreak or with Here-String (searched google), but with no success.

My code so far:

# location .xml files

$files = Get-ChildItem D:\test\*.xml

# value to search for $find = "<waarde/></telefoonNrWerk>"

# and replace the value with $replace = "<waarde>onbekend<waarde/></telefoonNrWerk>"

# command to do the work Foreach ($xmlfile in $files) { (Get-Content $xmlfile.Name) | Foreach-Object {$_ -replace $find, $replace} | Set-Content $xmlfile.Name }

Could anyone give me some help how to add the linebreak (if possible at all).



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>