Check IP Addresses Available in Azure Virtual Network

Check IP Addresses Available in Azure Virtual Network

Q. How can I check which IP addresses are available in an Azure virtual network?

A. If you are using reserved IP addresses in an Azure virtual subnet and want to quickly check which IP addresses are available, the Test-AzureStaticVNetIP cmdlet can be used as part of a PowerShell FOR loop to check for a range. In the code below, I check from 10.7.115.1 to 10.7.115.19. To change the range change the $networkID value and the host ID part in the FOR loop with the value you want.

#Check Available IP addresses
$networkID = "10.7.115."
For ($i=1; $i -lt 20; $i++) 
{
    $IP = $networkID + $i
    $Address = Test-AzureStaticVNetIP -VNetName VirtNet115 -IPAddress $IP
    If ($Address.IsAvailable –eq $False) { Write-Host "$IP is not available" -ForegroundColor Red } else { Write-Host "$IP is available" -ForegroundColor Green}
}

Below is an example execution.

You could change this code to output to a file instead of the screen by using write-output instead of write-host (since write-host cannot be redirected) and perhaps only output available addresses.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish