How To Manage Firewall Rules For Azure SQL Server Using PowerShell

Introduction

In my previous blog, you saw how to configure firewall rules for SQL Server on the Azure Portal. Azure SQL Database is a relational Database-as-a-Service which provides high performance, reliable, and secure database used to build data-driven applications and websites. In this blog, you will see how to manage firewall rules for SQL Server on Azure using PowerShell. You can either use Azure cloud shell to run PowerShell from your browser or you can install it on your computer.

SQL Server Details

Log in to the Azure Portal.

Click SQL Databases -> vijaiDB (which I have created in my previous article). Click Overview and you could see the server name and resource group which will be required for managing the firewall rules using PowerShell.

 

Open PowerShell from your browser

Log in to the Azure Portal.

Click Cloud Shell and then click PowerShell.

 

Create storage and once the storage is created, it will take a few minutes for the Cloud Shell to open the PowerShell session.
  

Get-AzureRmSqlServerFirewallRule cmdlet will get all the firewall rules for a SQL Database Server. 

  1. Get-AzureRmSqlServerFirewallRule -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103"    
 

Remove-AzureRmSqlServerFirewallRule cmdlet will delete a firewall rule from the SQL Database Server. 

  1. Remove-AzureRmSqlServerFirewallRule -FirewallRuleName "ClientIPAddress_2017-11-04_10:10:06" -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103"  
 

New-AzureRmSqlServerFirewallRule cmdlet will create a firewall rule for SQL Database Server.

  1. New-AzureRmSqlServerFirewallRule -FirewallRuleName "ClientIPAddress001" -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -StartIpAddress "68.199.241.153" -EndIpAddress "68.199.241.153"  
 

Set-AzureRmSqlServerFirewallRule cmdlet will modify the firewall rule in a SQL Database Server. 

  1. Set-AzureRmSqlServerFirewallRule -FirewallRuleName "ClientIPAddress001-NameUpdated" -ResourceGroupName "myResourceDB" -ServerName "mysqldbserver20171103" -StartIpAddress "68.199.241.153" -EndIpAddress "68.199.241.153"  
 

Result

Thus, in this blog, you saw how to manage firewall rules for SQL Server on Azure using PowerShell.