Get Azure VM IP address PowerShell

In this article, I’ll walk you through multiple proven methods to retrieve both public and private IP addresses of Azure VMs using PowerShell, using a simple PowerShell script, and the Azure Portal.

Get Azure VM IP address PowerShell

Before diving into the specific commands, let’s consider why PowerShell is often the preferred approach for retrieving Azure VM IP addresses:

  • Automation: Integrate IP retrieval into your deployment scripts and CI/CD pipelines
  • Bulk operations: Get IPs for multiple VMs simultaneously
  • Filtering: Easily target specific VMs or resource groups
  • Output customization: Format results exactly as needed
  • Cross-platform support: Works with PowerShell 7 across Windows, macOS, and Linux

Prerequisites

Below are the Prerequisites required before starting.

  1. PowerShell 5.1 or later (PowerShell 7+ recommended)
  2. Azure PowerShell module installed
  3. An active Azure subscription
  4. Appropriate permissions to view VM resources

If you haven’t set up the Azure PowerShell module yet, install it with:

Install-Module -Name Az -Repository PSGallery -Force

Once installed, connect to your Azure account:

Connect-AzAccount

Assuming you are ready with the above Prerequisites, let us start with the functionality.

Approach 1: Using a PowerShell script

You can easily retrieve the IP address of your Azure Virtual Machine using PowerShell using the below PowerShell script.

$vmdetailsreport = @()
$vmList = get-azurermvm
$vmnic = get-azurermnetworkinterface | ?{ $_.VirtualMachine -NE $null}
 
foreach($nic in $vmnic)
{
    $details = "" | Select VmName, ResourceGroupName, HostName, IpAddress
    $myvm = $vmList | ? -Property Id -eq $nic.VirtualMachine.id
    $details.VMName = $myvm.Name
    $details.ResourceGroupName = $myvm.ResourceGroupName
    $details.IpAddress = $nic.IpConfigurations.PrivateIpAddress
    $details.HostName = $myvm.OSProfile.ComputerName
    $vmdetailsreport+=$details
}

After executing the above query, I got the expected output as shown in the screenshot below.

how to get public ip address of azure vm using powershell

Approach 2: Using Azure Portal

To get Public IP address of Azure VM, follow the steps below.

  1. Log in to the Azure Portal (https://portal.azure.com/)
  2. Once you log in to the Azure Portal, Search for the Virtual Machine.
get public ip address of azure vm using powershell

3. Once you click on the search result in Virtual Machines, you can see all your virtual machines listed below. Click on the specific virtual machine for which you want to check the IP address.

change public ip address in azure vm

4. On the Virtual machine page, you can see the Public IP address highlighted below.

Get Azure VM IP address PowerShell

You can also click on the Networking option from the left navigation on the Virtual Machine page. You can see the Public and private IP addresses for the virtual machine as highlighted below.

change public ip address azure vm

5. By default, the IP address of the Azure Virtual Machine is dynamic. If you want to change the dynamic IP of the VM to a Static IP address, you can click on the IP address, as highlighted below.

change ip address azure vm

6. Now, in the window below, change the Assignment option from Dynamic to Static and click the Save button to save the changes. Now, the IP address of your Azure Virtual Machine has become Static.

how to change public ip address in azure vm

FAQs

Does Virtual Machine have its own IP address?

The answer is yesvirtual machines are similar to physical computers. A virtual machine can have one or more IP addresses. The IP address can be public or private. When discussing IP addresses in the context of Virtual Machines, they are closely associated with the network interfaces. Again, the Network interfaces with the Network adapters.

Final Thoughts

Retrieving Azure VM IP addresses using PowerShell is a fundamental skill for cloud administrators and DevOps engineers. Whether you’re managing a small environment or a large one, the methods mentioned in this article provide flexible, efficient approaches to accessing this critical information.

By mastering these approaches as mentioned in this article, you’ll be well-equipped to integrate IP address retrieval into your broader Azure automation workflows, saving time and reducing manual errors.

In this Azure article, we discussed the quick steps to get the IP address of your Azure Virtual Machine. Thanks for reading this article !!!

You may also like the following articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!