In this post I’ll show you how to Use PowerShell to enable Azure Storage Account Firewall Rules.

Be sure to be have AzureRM PowerShell 4.4.1 module installed.

Login to your Azure Account

Launch Powershell and start by Login to your Azure Account.

1    Login-AzureRmAccount

Set Resource Group and Storage Account Name Variables

Set the following variables

1    $resourceGroupName = "[THE NAME OF THE RESOURCE GROUP]"
2    $storageAccountName = "[THE NAME OF THE STORAGE ACCOUNT]"

Enable the Firewall

To enable the firewall you’ll need to Deny all trafic to the storage account using the DefaultAction parameter and then allow Azure Services to connect to it with the Bypass parameter.

1    Update-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $resourceGroupName -Name $storageAccountName -DefaultAction Deny -Bypass AzureServices,Metrics,Logging

To allow an IP Address or an IP Address range you can run the following commands changing the value of the IPAddressOrRange parameter:

1    Add-AzureRMStorageAccountNetworkRule -ResourceGroupName $resourceGroupName -AccountName $storageAccountName -IPAddressOrRange "79.159.46.90" 
1    Add-AzureRMStorageAccountNetworkRule -ResourceGroupName $resourceGroupName -AccountName $storageAccountName -IPAddressOrRange "79.159.46.0/24" 

Hope it helps!