VMware Cloud Community
foam
Enthusiast
Enthusiast
Jump to solution

Creating a report for VM's that do not have a tag

I am creating customer tags for all of my guests.  With attributes, I could just view the empty field under the VI Client.  Here I am kind of lost.  I can filter by vms with TAGs export that and remove those from a full list of guests but that is not very helpful.

I tried

$VMName = Get-VM NAME

if ($VMName.ExtensionData.Tag -ne $null) {Write-Host "yes"}

This works for a guest that has a tag.  When I change -ne to -eq it does not report back what I thought would be a null value.

(Note, this really does not work at all.  It sends back all guests, tagged or not.)

Can anyone shed some light on this?

Thank you.  Matt

0 Kudos
1 Solution

Accepted Solutions
foam
Enthusiast
Enthusiast
Jump to solution

$vmlist = get-vm 

$vmlist | where {(Get-TagAssignment $_).length -eq 0} | Sort-Object -Property name | ft name

This works!  Using the length of the empty array rather than $null.

View solution in original post

0 Kudos
1 Reply
foam
Enthusiast
Enthusiast
Jump to solution

$vmlist = get-vm 

$vmlist | where {(Get-TagAssignment $_).length -eq 0} | Sort-Object -Property name | ft name

This works!  Using the length of the empty array rather than $null.

0 Kudos