Category: Azure

Azure SQL Database Level Firewall Rules

If you have been using Azure SQL Servers and databases, you will already be aware that you need to configure the server level firewall. You may not know that you can also set firewall rules at database level too.
However this cannot be done through the Azure Portal. However both server and database level firewall rules can be easily managed using SQL.

Server Level

-- ========== SERVER LEVEL FIREWALL (master database connection)

-- List firewall rules
 SELECT * FROM sys.firewall_rules ORDER BY name;

 -- ADD Server firewall rule
 EXECUTE sp_set_firewall_rule @name = N'MyFirewallRule', @start_ip_address = '', @end_ip_address = ''

 -- DELETE Server firewall rule
 EXECUTE sp_delete_firewall_rule @name = N'MyFirewallRule'

Database Level

 -- ========== DATABASE LEVEL FIREWALL (specific database connection)

 -- List firewall rules
 SELECT * FROM sys.database_firewall_rules ORDER BY name;

 -- ADD Database firewall rule
 EXEC sp_set_database_firewall_rule @name = N'MyDBFirewallRule', @start_ip_address = '', @end_ip_address = ''

 -- DELETE Server firewall rule
 EXEC sp_delete_database_firewall_rule @name = N'MyDBFirewallRule'

See also

Finding Azure VM Images using PowerShell

I have been trying to write a PowerShell command that would help me find the right Azure VM Image to use when creating a new Virtual Machine.

In the Portal UI you get something not very useful like the following when search for a VM Image. No unique identifying information to locate the image from script.


However, when using such a simple search in PowerShell, you get a lot more data returned and working out which one you want is a bit of a pain.

After a few iterations I thought I would share it and save others the time.

The first thing is how to filter the huge list to just the images that contain what I am after, whether that’s a service or OS. It turns out that there is not much consistency to help here, but two fields stand out for searching.

  • Label – The publicly visible name of the image
  • ImageFamily – A sometimes useful category that can be used to filter, but depend on the type of image. Often this value is either the same as the Label or some cryptic value.

Once filtered, there seemed to be a number of additional fields that may vary and influence your decision as to which VM Image you want when creating a new VM.

  • OS – This is usually repeated in the Label so have left this off the listing.
  • PublisherName – Was hoping this may match the Portal listing, but no!
  • PublishedDate – The date the image was published. I have use this to sort the list, showing the latest first.
  • Category – I was also hoping this would match the Portal listing, but no! This seems to only indicate if the image is public or …something else! I am only interested in Public ones.
  • IsPremium – This indicates if the image includes any licensing. If false, it’s more than likely a ‘Bring You Own License’ (BYOL)
  • ShowInGui – I assume when this is ‘true’ then the image is available in the portal. Again I think unless you have a very specific image in mind, this should also be ‘true’.
  • RecommnededVMSize – sows the recommended VM size to use

I was looking for a simple “Windows Server 2016 Datacenter”. Ideally the recommended or default. For this case it was possible to filter by the ImageFamily. However I noticed this was not going to be so easy for other things such as ‘SQL Server’ images as some ImageFamily were return with text like ‘Windows SQL14-PCU-MAIN-12.0.5000.0-SQLENTCORE.ENU.Nov-WS2012R2-127gb.’ , so opted for filter on the Label instead.

$searchTerm = "*Windows Server 2016*"
Get-AzureVMImage | Where-Object {$_.Label -like $searchTerm -and $_.Category -eq "Public" -and $_.ShowInGui -ne $false} | Sort-Object PublishedDate -Descending | Select-Object Label,PublisherName, PublishedDate,IsPremium,RecommendedVMSize,ImageName | Format-Table

The line above will produce a table output as shown below, but the ImageName, which is probably what you are after, may well be truncated.

$searchTerm=”*SQL Server 2014*”


$searchTerm=”*Windows Server 2016 Datacenter*”

So, once you have honed your search term down, then run this smaller table version.

Get-AzureVMImage | Where-Object {$_.Label -like $searchTerm -and $_.Category -eq "Public" -and $_.ShowInGui -ne $false} | Sort-Object PublishedDate -Descending | Select-Object Label,ImageName | Format-Table

which produces something like the listing below, from where you can copy the full ImageName.



Awesome Tool and Diagnostic Util

I just found this very useful tool, especially if you are dealing with Azure VMs.


This is the tool used by the Azure Developer Support Team. You can install it while on a VM using Powershell by running the following in a Powershell command window:

md c:\tools; Import-Module bitstransfer; Start-BitsTransfer c:\tools\AzureTools.exe; c:\tools\AzureTools.exe

For more info see