Azure cli 使用标签过滤实例

Azure cli to filter Instances using tags

我正在尝试根据标签过滤实例,但它为我提供了资源组中存在的所有实例。我需要列出具有特定标签的实例。我正在使用以下命令列出具有 wknhscale == 'active' 标记的实例,该命令有问题吗?还有其他有效的方法吗?

az vm list --query '[?tags.wknhscale == 'active'].{Name:name, RG:resourceGroup}' -o table

我正在寻找一个简单的查询来获取带有标签的实例,就像在 gcp 中一样

gcloud compute instances list --project test --filter='labels.wknhscale:active AND name ~ .*wkn*' --sort-by=creationTimestamp --format='value(name,zone)'

我建议为此使用 Azure Resource Graph。资源图允许您在 CLI 或门户中使用 Kusto 语言查询所有 Azure 资源(在您有权访问的所有订阅中)。

我能够使用 az 图查询进行查询。谢谢,@azMantas

az graph query -q "Resources |  where type =~ 'Microsoft.Compute/virtualMachines' | where tags['wknhscale']=='active' |  where name startswith 'workernode' | project name | order by name asc" | jq '.data[].name'