Powershell - Finding IP of VM from Azure portal (AZ Module)

Powershell - Finding IP of VM from Azure portal (AZ Module)

How to find the private IP address of VM in AZ Module

Step 1: Find your VM details 

$VM = Get-AzVm -name "Your VM Name"

Step 2: Set the NetworkInterface Profile to a variable. The NeworkInterfaceID will be having a value separated by "/" and profile name at the end. 

$Profile =$VM.NetworkProfile.NetworkInterfaces.Id.Split("/") | Select -Last 1

Step 3: From ProfileName we will fetch the networkinterface details to a variable

$IPConfig = Get-AzNetworkInterface -Name $Profile

Step 4: The following will have the Private IP address value configured for the specific VM

$IPAddress = $IPConfig.IpConfigurations.PrivateIpAddress

Note: If multiple NIC are attached to a VM, you will have to loop in Step 2 
Comments
  • foreach ( $azVM in Get-AzVM ) {

       #$azVm

       $networkProfile = $azVm.NetworkProfile.NetworkInterfaces.id.Split("/")|Select -Last 1

       $IPConfig = (Get-AzNetworkInterface -Name $networkProfile).IpConfigurations.PrivateIpAddress

       [pscustomobject]@{

           fqdn = $azVm.OsProfile.ComputerName

           ipaddress = $IPConfig

       }

    }

Page 1 of 1 (1 items)