Skip to content

Instantly share code, notes, and snippets.

@mikaelweave
Created August 30, 2017 16:25
Show Gist options
  • Save mikaelweave/a025e8439cd700c0e46e4881214efcb0 to your computer and use it in GitHub Desktop.
Save mikaelweave/a025e8439cd700c0e46e4881214efcb0 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment