Created
March 22, 2016 06:02
-
-
Save Manu-pocs/04b3623695b5f3ef0553 to your computer and use it in GitHub Desktop.
To create SQL Server in Azure Environment
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
| <# | |
| .SYNOPSIS | |
| To create SQL Server in Azure Environment | |
| .DESCRIPTION | |
| This script creates a new SQL Server in the Azure Environment | |
| .EXAMPLE | |
| .\CreateSQLServer.ps1 -AzureSubscriptionName "dt - Dev" -ResourceGroupName RG-Dev-Storage-WestEurope -ServerName myPSTestsqlserver -Location "West Europe" | |
| #> | |
| [CmdletBinding(SupportsShouldProcess = $true)] | |
| param( | |
| # The name of valide Azure Subscription associated with Account | |
| [Parameter(Mandatory = $true)] | |
| [string]$AzureSubscriptionName, | |
| # The name of the Resource Group | |
| [Parameter(Mandatory = $true)] | |
| [string]$ResourceGroupName, | |
| # The name of the SQL Server name on which database will be imported. | |
| [Parameter(Mandatory = $true)] | |
| [string]$ServerName, | |
| # The Azure Data center Location | |
| [Parameter(Mandatory = $true)] | |
| [string]$Location | |
| ) | |
| # The script has been tested on Powershell 3.0 | |
| Set-StrictMode -Version 3 | |
| [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials | |
| # To authenticate through Windows Azure Active Directory and downloads associated subscriptions. | |
| Add-AzureRmAccount | |
| # To select specific subscription from available subscription "Visual Studio Enterprise with MSDN" | |
| Select-AzureSubscription -SubscriptionName $AzureSubscriptionName | |
| # Check if Windows Azure Powershell is avaiable | |
| if ((Get-Module -ListAvailable Azure) -eq $null) | |
| { | |
| throw "Windows Azure Powershell not found! Please install from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools" | |
| } | |
| else | |
| { | |
| Write-Host "Windows Azure Powershell is available!!!" | |
| } | |
| #Running the Get-Credential cmdlet opens a window asking for your username and password. Enter the admin login and password for the SQL server you want to create the database in $ServerName | |
| $credential = Get-Credential | |
| # Create Database Server | |
| Write-Host "Creating SQL Azure Database Server." | |
| # $databaseServer = New-AzureSqlDatabaseServer -AdministratorLogin $credential.UserName -AdministratorLoginPassword $credential.GetNetworkCredential().Password -Location $Location | |
| $databaseServer = New-AzureRmSqlServer -ResourceGroupName $ResourceGroupName -ServerName $ServerName -SqlAdministratorCredentials $credential -Location $Location -ServerVersion "12.0" | |
| Write-Host ("SQL Azure Database Server '" + $databaseServer.ServerName + "' created.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment