Configure Azure Website Connection Strings with PowerShell
# Sign in to Azure through the UI Add-AzureAccount # Inspect existing connection strings $connStrings = (Get-AzureWebsite website-name-here).ConnectionStrings Write-Host ($connStrings | Format-List | Out-String) # Create new connection string # Type must be one of MySql, SQLServer, SQLAzure, Custom $newConnString = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.ConnStringInfo $newConnString.Name = "connection-string-name-here" $newConnString.ConnectionString "connection-string-here" $newConnString.Type = "SqlAzure" # Change an existing connection string by name $connStrings.Find({ param($m) $m.Name.Equals("connection-string-name-here") }).ConnectionString = 'onnection-string-here' # Change an existing connection string with variables $newPassword = 'SUPER_DUPER_SECURE_PASSWORD_HERE' # single quotes for literal $websiteName = "" $dbName = "" $connStringName = "" $connString = "Data Source=tcp:abcdefghi.database.windows.net,1234;Initial Catalog=$($dbName);User ID=whoami@abcdefghi;Password=$($newPassword)" $connStrings = (Get-AzureWebsite $websiteName).ConnectionStrings $connStrings.Find({ param($m) $m.Name.Equals($connStringName) }).ConnectionString = $connString Set-AzureWebsite $websiteName -ConnectionStrings $connStrings # push – BE CAREFUL THIS GOES LIVE $connStrings.Add($newConnString) Set-AzureWebsite website-name-here -ConnectionStrings $connStrings
See also
- http://azure.microsoft.com/blog/2013/07/17/windows-azure-web-sites-how-application-strings-and-connection-strings-work/
- http://stackoverflow.com/questions/15792650/printing-object-properties-in-powershell
- http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/
- http://stackoverflow.com/questions/7342597/how-do-you-comment-out-code-in-powershell
- http://stackoverflow.com/questions/10503184/how-to-removeall-when-using-generic-listt-in-powershell