bonafide
bonafide

Reputation: 368

How to query all VMs in a subscription without Tags

I want to be able to query all the VMs in my Azure subscription to list machines that do not have Tags.

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

Above code shows all the resources without Tags (nic, lb, etc.) I only want to see Virtual Machines

Upvotes: 3

Views: 1553

Answers (1)

4c74356b41
4c74356b41

Reputation: 72211

I'd use this:

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

which is a easier to read\understand

edit: sorry, you need the reverse:

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

Upvotes: 3

Related Questions