Prerequisites
- Windows Azure PowerShell.
- An active Azure subscription.
Steps to create a blank database using Windows PowerShell commands
Step 1
Run Windows PowerShell as an administrator.
Step 2
Now, we need to login into Azure subscription by using Windows Azure PowerShell. I have provided Azure PowerShell commands. Login into Azure, using command script. You can change the admin name, password etc.
Add-AzureRmAccount
Step 3
After following the command given above, a login page will appear for an Azure portal, so that after logging into the Azure portal, we need to create a resource group with the location of the database storage.
Now provide an admin login and a password for the database. Provide a database name and the IP which is provided is based on the user’s request. To create the Server with an admin name and the password with the database name, PowerShell script is given below.
- #The data center and resource name
- for your resources
- $resourcegroupname = "myResourceGroup"
- $location = "WestEurope"
- #The logical server name: Use a random value or replace with your own value(do not capitalize)
- $servername = "server-$(Get-Random)"
- #Set an admin login and password
- for your database# The login information
- for the server
- $adminlogin = "ServerAdmin"
- $password = "ChangeYourAdminPassword1"
- #The ip address range that you want to allow to access your server - change as appropriate
- $startip = "0.0.0.0"
- $endip = "0.0.0.1"
- #The database name
- $databasename = "mySampleDatabase"
Step 4
The resource group is a container to manage and deploy Azure resources so that we need to create a resource group with the command. Thus the command leads to the creation of the resource group and with the location of the database.
- New-AzureRmResourceGroup -Name $resourcegroupname -Location $location
Step 5
Creating a logical Server leads to contain the group of database managed in the group. The creation of a logical Server is followed by the new-azureRmsqlServer command. You can replace the admin name and the password in the predefined values, as per your desire.
- New-AzureRmSqlServer -ResourceGroupName $resourcegroupname `
- -ServerName $servername `
- -Location $location `
- -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminlogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))
Step 6
A Server Firewall allows an external application such as SQL server management studio to connect to SQL database through the SQL database Service Firewall and is created by using New-AzureRmSQLServerFirewallRule command.
- New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourcegroupname `
- -ServerName $servername `
- -FirewallRuleName "AllowSome" -StartIpAddress $startip -EndIpAddress $endip
Step 7
The configuration of the database with the Server Firewall finishes. Now, we need to create a blank database through the command New-AzureRmSqlDatbase given below.
- New-AzureRmSqlDatabase -ResourceGroupName $resourcegroupname `
- -ServerName $servername `
- -DatabaseName $databasename `
- -RequestedServiceObjectiveName "S0"
Hence, I hope you learned to create a blank database, using Windows PowerShell, and thanks for reading.