Created
February 20, 2017 10:30
-
-
Save raducugheorghe/554d23dced9ff2cca189c958c5f8aec5 to your computer and use it in GitHub Desktop.
Change EF database name in connection string tool
This file contains 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
$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