PowerShell script t...
 
Notifications
Clear all

PowerShell script that you can use to whitelist a list of IP addresses

Raju
 Raju
(@raju)
Member Admin

PowerShell script that you can use to whitelist a list of IP addresses to an Azure storage account:

# Set the storage account name
$storageAccountName = "<storage-account-name>"

# Set the resource group name
$resourceGroupName = "<resource-group-name>"

# Set the list of IP addresses to whitelist
$ipAddresses = @("<ip-address-1>", "<ip-address-2>", "<ip-address-3>")

# Get the storage account object
$storageAccount = Get-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName

# Get the network rules object for the storage account
$networkRules = Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $resourceGroupName -Name $storageAccountName

# Add the IP addresses to the whitelist
foreach ($ipAddress in $ipAddresses) {
  $networkRules.IPRules.Add($ipAddress)
}

# Update the storage account with the new network rules
$storageAccount | Set-AzStorageAccountNetworkRuleSet -NetworkRuleSet $networkRules

This script assumes that you have already installed the Azure PowerShell module and authenticated with your Azure account. If you have not done this, please follow the instructions here to install the module and authenticate.

Note that this script will add the specified IP addresses to the whitelist for the storage account. If the storage account already has a whitelist, the IP addresses will be added to the existing whitelist. This script will not remove any existing IP addresses from the whitelist.

This topic was modified 1 year ago by Raju
Quote
Topic starter Posted : 05/12/2022 9:02 pm
Share: