Search code examples
azurepowershellazure-virtual-machineazure-powershell

How do I find the network interface ID associated with an Azure VM


I can find the VM by using

$vm = Get-AzureRmVM -ResourceGroupName "MyResource" -Name "MyVM"

But how can I find the network interface associated with this VM?


Solution

  • Once you have your VM in a variable $vm (as shown below)

    $vm = Get-AzureRmVM -ResourceGroupName "MyResource" -Name "MyVM"
    

    You can get the NIC by finding the interface that matches the ID from your VM

    $nic = Get-AzureRmNetworkInterface 
           | Where {$_.Id -eq $vm.NetworkProfile.NetworkInterfaces[0].Id}