简体   繁体   English

附加到VM的azure cli list nic

[英]azure cli list nic attached to VM

I am working on bash shell. 我正在研究bash shell。 I need az cli or unix script to find out NIC name attached to particular VM. 我需要az cli或unix脚本来找出附加到特定VM的NIC名称。 I know VM name and VM Resource Group Name and my Target is to findout out which NIC is attached to this VM and which resouce group this NIC belongs to? 我知道虚拟机名称和虚拟机资源组名称,我的目标是找出该虚拟机连接了哪个网卡以及该网卡属于哪个资源组?

az vm nic list --resource-group --vm-name [--subscription] az vm nic列表--resource-group --vm-name [--subscription]

This will list all nics on a vm. 这将列出虚拟机上的所有NIC。

eg. 例如。 az vm nic list -g MyResourceGroup --vm-name MyVm az vm nic列表-g MyResourceGroup --vm-name MyVm

Please follow this line of azure cli code: 请遵循以下蔚蓝cli代码行:

Step 1: Define a variable, like a . 步骤1:定义一个变量,像a Note that there is no whiteSpace around the chars = : 请注意,在chars =周围没有空白

a="$(az vm nic list --resource-group "your_resource_group" --vm-name "your_vm_name" --query "[].{id:id}" --output tsv)"

在此处输入图片说明

Step 2: Just get the nic name and it's resource group: 步骤2:只需获取nic名称及其资源组即可:

az vm nic show -g "your_resource_group" --vm-name "your_vm_name" --nic $a --query "{name:name,resourceGroup:resourceGroup}" --output table

在此处输入图片说明

Step 3: If you want get all the information of nic, please use the code below: 步骤3:如果要获取nic的所有信息,请使用以下代码:

az vm nic show -g "your_resource_group" --vm-name "your_vm_name" --nic $a

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM