Find Available Addresses Within an Azure Subnet

Find Available Addresses Within an Azure Subnet


I recently had to rebuild a customers Web Application Firewall cluster in parallel so the new infrastructure can coexist without affecting the original. As this was a 3 node cluster and each node has multiple IP configurations, I needed to understand what addresses were free so I could configure the new firewalls. A relatively simple task yet I could not find an easy way within Azure to find this information in one place. So I decided to do some custom scripting to find this information.


In order to use the script you will need thew following:

  • A copy of the Get-IPRange.ps1 file located on Technet here
  • The Azure AZ Modules
  • Details of your VNET, VNET Resource Group and Subnet name

The script

The script is simple and performs the following:

  • Logs into Azure and retrieves the VNET and subnet information
  • Calculates the IPs within the CIDR Range on the subnet
  • Determines which IPs are free by calling the Test-AzPrivateIPAddressAvailability CmdLet

Next steps

It seems that the Test-AzPrivateIPAddressAvailability only accepts one IP at a time so the script can take a while to return the results, particularly on larger subnet ranges. Perhaps the subnet range could be split into smaller chunks and the test executed asynchronously using PS Jobs. This code did the job for me though and I was able to rebuild the firewalls with new IPs.

Leave a Reply

Your email address will not be published. Required fields are marked *