Replace Connection Strings
param([string]$oc,[string]$nc)
Write-Host "Searching for: "$oc
Get-ChildItem test.config -recurse |
Foreach-Object {
$c = ($_ | Get-Content)
$n = $c -replace [RegEx]::Escape($oc), $nc
if($c -ne $n) {
Write-Host $_.FullName
if($nc -ne $NULL) {
Write-Host " Replacing $oc with $nc"
[IO.File]::WriteAllText($_.FullName, ($n -join "`r`n"))
}
}
}
Invoke like
.\ConnectionChange.ps1 -oc aspen\reporting -nc dw
oc: old connection
nc: new connection