Reputation: 368
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
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