Created
August 30, 2017 16:25
-
-
Save mikaelweave/a025e8439cd700c0e46e4881214efcb0 to your computer and use it in GitHub Desktop.
Replace Connection Strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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