I am trying to replace a line in a config file. The line has a | in it and when I try to run my script it inserts the new line after the first | instead of replacing the full line. Below is my code
$list = "C:\zworkingfolders\servers.txt"
$computers = get-content $list
foreach ($server in $computers)
{
# This script is used to make changes to the web.configs for the PTVDataService servers in Production
# Backup web.config in PTVDataService folder
copy-Item "\\$server\c$\program files\SupportSite\PTVDataService\web.config" -Destination "\\$server\c$\program files\SupportSite\PTVDataService\web$(get-date -f yyyy-MM-dd).config"
# Update web.config in PTVDataService folder
get-content "\\$server\c$\program files\SupportSite\PTVDataService\web$(get-date -f yyyy-MM-dd).config" | ForEach-Object {$_ -replace '<add key="RGN_0170"value="Oracle,10.132.18.115|10.132.18.116,0037,epc02p_svc1,P,EPCLOS2PTV"/>',' <add key="RGN_0170"value="ORACLE,dc2prtsf2-scan.es.ad.adp.com|dc2prtsf2-scan.es.ad.adp.com,0037,epc22p_svc1,P,EPCLOS2PTV"/>'} | Set-content "\\$server\c$\program files\SupportSite\PTVDataService\web.config"
}