Vivek Mishra
Vivek Mishra

Reputation: 11

Number of avaliable ips in azure subnet

I am looking for number of available IP addresses in each subnet in azure vnet so I am trying below script but I am not getting any option to get available IP.

$nic = Get-AzureRmVirtualNetwork -Name TST-VNET1 -ResourceGroupName TST-RG1
$nic.AddressSpace.AddressPrefixes
$subnets= $nic.Subnets
$subnets
foreach( $subnet in $subnets)
{
$subnet.Name
$subnet.IpConfigurations.Count
$subnet.AddressPrefix
}

Using $subnet.IpConfigurations.Count gets the usable IP addresses. $subnet.AddressPrefix gets the cidr.

I am looking here available or assigned host IP addresses in each subnet pool.

Upvotes: 0

Views: 4146

Answers (1)

Jason Ye
Jason Ye

Reputation: 13954

We can use Azure portal to get the number of available IP addresses: enter image description here

PowerShell script:

$nic = Get-AzureRmVirtualNetwork -Name "jason" -ResourceGroupName "vnet"
$nic.AddressSpace.AddressPrefixes
$subnets = $nic.Subnets
$subnets
foreach( $subnet in $subnets)
{
$subnet.Name
$subnet.IpConfigurations.Count
$subnet.AddressPrefix
}

$splitAddress = $subnet.AddressPrefix.Split("/") 
$output = [math]::Pow(2, (32 - $splitAddress[1])) - 5 - $subnet.IpConfigurations.Count

Upvotes: 1

Related Questions