You can try:
$xml = [xml](Get-Content c:\temp\web.config) $conString = $xml.connectionStrings.add[0].connectionString $conString2 = $conString -replace '192.168.1.100','10.10.10.10' $xml.connectionStrings.add[0].connectionString = $conString2 $conString = $xml.connectionStrings.add[1].connectionString $conString2 = $conString -replace '192.168.1.100','10.10.10.10' $xml.connectionStrings.add[1].connectionString = $conString2 $xml.Save('c:\temp\web2.config')
This task is for two connection strings. If you do not want to hardcode the old IP address you can use:
$conString -replace 'Server=.*;','Server=10.10.10.11;'
source share