如何在没有标签的情况下查询订阅中的所有虚拟机

How to query all VMs in a subscription without Tags

我希望能够查询我的 Azure 订阅中的所有 VM,以列出没有标签的机器。

$resources = Get-AzureRmResource
foreach($resource in $resources)
{
    if ($resource.Tags -eq $null)
    {
        echo $resource.Name, $resource.ResourceType
    }
}

上面的代码显示了所有没有标签的资源(nic、lb 等)我只想看虚拟机

我会用这个:

Get-AzureRMVM | Where-Object { $_.tags }

哪个更容易 read\understand

编辑:抱歉,您需要反转:

Get-AzureRMVM | Where-Object { $_.tags.count -eq 0 }