Skip to content

Instantly share code, notes, and snippets.

@raducugheorghe
Created February 20, 2017 10:30
Show Gist options
  • Save raducugheorghe/554d23dced9ff2cca189c958c5f8aec5 to your computer and use it in GitHub Desktop.
Save raducugheorghe/554d23dced9ff2cca189c958c5f8aec5 to your computer and use it in GitHub Desktop.
Change EF database name in connection string tool
$files = Get-ChildItem -Include Web.config -recurse | Select-String -pattern 'Database=[a-zA-Z_0-9\-]+;' | select path,matches
if ($files.length -eq 0 )
{
Write-Host "no files found" -ForegroundColor red
exit 0
}
Write-Host "Found the following matches:" -ForegroundColor green
$files | ConvertTo-JSON | Write-Host
$db = Read-host -Prompt "New database name"
Write-Host "Settings database to $($db):" -ForegroundColor green
$files | Foreach-Object {$content = Get-Content $_.path; $content | Foreach-Object {$_ -replace 'Database=[a-zA-Z_0-9\-]+;',"Database=$($db);"} | Set-Content $_.path -force }
Get-ChildItem -Include Web.config -recurse | Select-String -pattern 'Database=[a-zA-Z_0-9\-]+;' | select path,matches| ConvertTo-JSON | Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment