Saturday, August 23, 2025

Fixing Azure CLI Storage Account Whitelisting Error: ‘IPs does not appear to be an IPv4 or IPv6 network

This blog explains an error that occurs when whitelisting IPs on a storage account using an Azure CLI script. The script attempts to pass the IPs as a space-separated string and apply them through the CLI. However, it fails with an error indicating that the IP format is incorrect. This post explains the issue and provides the steps to fix it.

Pre-requites:

  • Azure Storage account
  • The $ipList parameter accepts a semicolon-separated list of IP addresses

  • Below is the CLI script that gives an error. The script accepts two string parameters, ipList and subscriptionId. The ipList parameter contains a semicolon-separated list of IPs. The script splits this string into an array of IP addresses and stores it in the ips variable. It then passes these IPs to the apply_storage_ip_rules function to whitelist the IPs on the specified storage account.

param(
    [string]$ipList,
    [string]$subscriptionId
)

function apply_storage_ip_rules 
{
    param (
        [string]$ips
    )

    Write-Host "Applying developer IP $ips to storage account";
    az storage account network-rule add --account-name 'demostorage' --resource-group 'demo-rg' --ip-address $ips --subscription $subscriptionId
}

$ips = $ipList -split ';';
apply_storage_ip_rules -ips $ips;


  • After running the script we get below error.

Applying developer IP 117.16.117.9 118.206.146.84 to storage account
ERROR: '117.16.117.9 118.206.146.84' does not appear to be an IPv4 or IPv6 network

  • As a fix, we need to change the ips parameter type to a string array. This way, the IPs will be applied to the storage account without causing an error.

    param (
        [string[]]$ips
    )


  • Below is the working script.

param(
    [string]$ipList,
    [string]$subscriptionId
)

function apply_storage_ip_rules 
{
    param (
        [string[]]$ips
    )

    Write-Host "Applying developer IP $ips to storage account";
    az storage account network-rule add --account-name 'demostorage' --resource-group 'demo-rg' --ip-address $ips --subscription $subscriptionId
}

$ips = $ipList -split ';';
apply_storage_ip_rules -ips $ips;


No comments:

Post a Comment