How to retrieve the Azure VM nic name using Azure CLI in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To get the Azure VM NIC name using Azure CLI, use the below command but before running the command make sure that you are connected to the Azure Account and the proper Azure subscription using Azure CLI.

az vm show -n AzureVM -g ResourceGroup --query
'[networkProfile.networkInterfaces][].id' -otsv

We need the NIC name from this. If you are running the Azure CLI in the PowerShell terminal then use the command below.

PS C:\> $nicinfo = az vm show -n VMname -g RGName --query
'[networkProfile.networkInterfaces][].id' -otsv
PS C:\> ($nicinfo.Split('/'))[-1]
Updated on 01-Sep-2021 09:49:50