Powershell: Create SQL Server in Microsoft Azure 1


In The previous article we discussed about Automation: Powershell Script to Import database in Microsoft Azure

 <#

.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”
#>

Powershell Script to create SQL Server in Microsoft Azure

[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.”)


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Powershell: Create SQL Server in Microsoft Azure