Check IP Addresses Available in Azure Virtual Network
Check the IP addresses available within Azure virtual networks.
March 10, 2015
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.
About the Author
You May Also Like