PowerShell based IPAM for the Azure IaaS cloud

Cover

When you configure your Azure VM with a static IP address, actually you are creating a DHCP reservation for the Azure infra DHCP service.

01.Get-AzSubnet_ipconfig

With a time, you will need to manage your growing Azure IaaS IP infra. In other words, you will need reliable IPAM (IP Address Management) solution.

The problem is you may not query Azure DHCP server(s) Emoj. In other hand I would not query VM guests for IP info, especially when the guests sometimes are stopped/deallocated Emoj.

The last and reliable way is PowerShell!

Get-AzSubnet

  • The Get-AzSubnet function from my Azure Automation Az-Module can be your IPAM solution.

  • The Azure network objects hierarchy is VirtualNetwork -> Subnet -> NetworkInterface. The last contains IP related info and linked (or not) to a VM. Why not? Because in the Azure the NetworkInterface is independent object and not VM child object, like in the VMware for example!

Select-AzObject VNET | Get-AzSubnet | Format-Table –AutoSize

02.Get-AzSubnet

Expand BusyIP property

  • To get all busy/leased IP in a particular Subnet, specify desired subnet by -Name parameter and expand BusyIP property by -ExpandProperty parameter of Select-Object cmdlet.
Select-AzObject VNET | Get-AzSubnet -Name $SubnetName | Select-Object -ExpandProperty BusyIP

03.Get-AzSubnet_expandBusyIP

  • The IP address list is sorted by Sort-IpAddress function, included in the module.

Is IP busy?

  • The BusyIP property is array of IP addresses and can be very long. If you only need to know is particular IP busy or not on the Subnet, you can query the BusyIP property with -contains operator.
Select-AzObject VNET | Get-AzSubnet -Name $SubnetName | ? {$_.BusyIP -contains '172.31.67.10'}

04.Get-AzSubnet_IsBusyIP

  • In above example the 172.31.67.13 IP is busy and 172.31.67.10 is not in use (no output).

Select-AzSubscription

  • If you notice the title bar in all my screenshots, this is result of Select-AzSubscription function with -Title parameter. Every time you move from one Azure Subscription to another, the function renew your PowerShell console title bar with newly selected Subscription name.
Select-AzSubscription -Title

Summary

  • For more details about the function, please take a look at the content based help and examples.
Get-Command -Module Az-Module
Get-Alias –Definition Get-AzSubnet
Get-Help Get-AzSubnet -Full
Get-Help Get-AzSubnet -Examples
Get-Help Get-AzSubnet -Parameter Name

You might also like

Azure VM Tag automation
How to login to the Azure automatically
How to find orphaned VHD files in the Azure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s