1

How To Get Azure RM VM IP Addresses Using PowerShell

This is a follow-up to the initial post on the topic which was based on the original Azure Service Manager (Azure SM) model.  Azure Resource Manager (Azure RM) changes the deployment methodology.  Take a look at Azure Resource Manager vs. classic deployment: Understand deployment models and the state of your resources for more details. We will take a brief look at the relationship of the networking objects to understand why the previous PowerShell commands will no longer work.

Azure Service Manager Network Resources

The below diagram shows the relationships of the Azure Service Manager network framework.  Note that the IP address is associated to the VM.

Azure Service Manager Network Relationships

 

As noted in the previous post we could use something like the below to get a list of all the VMs and their associated IP addresses in a given Cloud Service:

Get-AzureVM -ServiceName TailspinToysCanada | Select-Object Name, *IP* | Format-Table –AutoSize

Retrieving VM IP Address Information From Cloud Service

Note – only the two DCs were running when this information was captured.  The other VMs were in a StoppedDeallocated state.

 

Azure Resource Manager Network Resources

The Azure RM relationships are rather different than classic Service Manager deployments.  For the purposes of this discussion, note that IP addresses are no longer directly associated to the VM.  They are now held in an IP Configuration which is associated to the Network Interface. Also since there are no longer Cloud Services in the Azure RM world, things need adjustment…

Azure Resource Manager Network Relationships

 

 

Obtaining Azure RM VM IP Address Information

Bearing in mind there are no Cloud Services in Azure RM, we need a different tack.  Using the Get-AzureRmNetworkInterface cmdlet we can use the –ResourceGroupName parameter to work with a subset of the given VM Network Interfaces as they will be in different Resource Groups.  This can be edited/adjusted to suit your requirements.  You many not have all the resources in the same Resource Group, so that may also have to be adjusted to suit your environment.

From the list of Network Interfaces, we can then pass the interface down the pipeline to the Get-AzureRmNetworkInterfaceIpConfig  cmdlet.  This is then used to retrieve the PrivateIPAddress from the IP Configuration.  This is done as a one-liner, but could be split out into a script if you so desire..

Double click the code to make it easier to copy out.

Get-AzureRmNetworkInterface -ResourceGroupName Rmilne-Tailspintoys-Canada | ForEach { $Interface = $_.Name; $IPs = $_ | Get-AzureRmNetworkInterfaceIpConfig | Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress }

 

Retrieving VM IP Address Information From Azure RM VM

The output is written out to include the interface name in addition to the associated PrivateIPAddress

Cheers,

Rhoderick

Rhoderick Milne [MSFT]

One Comment

Leave a Reply

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