Can we get the details of Virtual Machine using Private IP Address in Azure Portal?

Bhardwaj, Rajeev 105 Reputation points
2023-12-06T06:24:15.0433333+00:00

Dear Community,

I have a requirement to get the details of Virtual Machine using Private IP Address in Azure Portal. I tried but it not working.

Is there any way to get the details of Virtual Machine using Private IP Address in Azure Portal?

Thanks & Regards,

Rajeev

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,515 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olga Os - MSFT 5,841 Reputation points Microsoft Employee
    2023-12-06T21:27:09.4433333+00:00

    Hello Bhardwaj, Rajeev,

    Welcome to the MS Q&A Forum.

    If I'm understanding your question correctly, you're asking for the simplest way to locate the list of VMs and their private IP addresses. One way to do this is by going to the Virtual Machines blade => "Manage View" => "Edit columns" and adding the relevant columns there. Here's an example to help you understand better:User's image

    I hope this helps! Kindly mark the answer as Accepted and Upvote in case it helped. Regards,

    Olga Os.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. msrini-MSFT 9,271 Reputation points Microsoft Employee
    2023-12-06T09:02:23.6566667+00:00

    Hi,

    You can use the below Powershell script to get what you are asking for:

    # Install and import the Azure PowerShell module if not already installed
    Install-Module -Name Az -Force -AllowClobber -Scope CurrentUser
    Import-Module Az -Force
    
    # Connect to your Azure account (sign in if prompted)
    Connect-AzAccount
    
    # Define the IP address to check
    $ipToCheck = "X.X.X.X"  # Replace with the IP address you want to check
    
    # Get all virtual networks in the subscription
    $virtualNetworks = Get-AzVirtualNetwork
    
    foreach ($virtualNetwork in $virtualNetworks) {
        $resourceGroupName = $virtualNetwork.ResourceGroupName
        $virtualNetworkName = $virtualNetwork.Name
    
        # Get all connected devices (VMs) in the virtual network
        $connectedDevices = Get-AzNetworkInterface -ResourceGroupName $resourceGroupName | Where-Object {
            $_.VirtualNetwork.id -eq $virtualNetwork.id
        }
    
        # Check if the given IP is part of any connected device
        $ipIsConnectedDevice = $connectedDevices | ForEach-Object {
            $ipConfigurations = $_.IpConfigurations | ForEach-Object { $_.PrivateIpAddress }
            $ipToCheck -in $ipConfigurations
        }
    
        if ($ipIsConnectedDevice) {
            Write-Host "The IP address $ipToCheck is part of the connected devices in the Azure Virtual Network '$virtualNetworkName' (Resource Group: $resourceGroupName)."
        } else {
            Write-Host "The IP address $ipToCheck is not part of the connected devices in the Azure Virtual Network '$virtualNetworkName' (Resource Group: $resourceGroupName)."
        }
    }
    
    # Disconnect from Azure (optional)
    Disconnect-AzAccount