Create A Blank Database Using PowerShell

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 

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. 

  1. #The data center and resource name  
  2. for your resources  
  3. $resourcegroupname = "myResourceGroup"  
  4. $location = "WestEurope"  
  5. #The logical server name: Use a random value or replace with your own value(do not capitalize)  
  6. $servername = "server-$(Get-Random)"  
  7. #Set an admin login and password  
  8. for your database# The login information  
  9. for the server  
  10. $adminlogin = "ServerAdmin"  
  11. $password = "ChangeYourAdminPassword1"  
  12. #The ip address range that you want to allow to access your server - change as appropriate  
  13. $startip = "0.0.0.0"  
  14. $endip = "0.0.0.1"  
  15. #The database name  
  16. $databasename = "mySampleDatabase"   
Azure portal 
 PowerShell script

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.

  1. New-AzureRmResourceGroup -Name $resourcegroupname -Location $location   

 create azure resource group

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. 

  1. New-AzureRmSqlServer -ResourceGroupName $resourcegroupname `  
  2. -ServerName $servername `  
  3. -Location $location `  
  4. -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminlogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))   
 create logical Server

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.

  1. New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourcegroupname `  
  2. -ServerName $servername `  
  3. -FirewallRuleName "AllowSome" -StartIpAddress $startip -EndIpAddress $endip   
 New-AzureRmSQLServerFirewallRule

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.

  1. New-AzureRmSqlDatabase -ResourceGroupName $resourcegroupname `  
  2. -ServerName $servername `  
  3. -DatabaseName $databasename `  
  4. -RequestedServiceObjectiveName "S0"   
 New-AzureRmSqlDatbase

Hence, I hope you learned to create a blank database, using Windows PowerShell, and thanks for reading.