VMware Cloud Community
jfierberg
Contributor
Contributor
Jump to solution

powercli script retrieve vmname based on custom field value

I want to retrieve a set of virtual machine names based on a custom attribute.  I have a custom field called Alert Level and I want to list only those servers with an alert level of 4 so that i can automatically shut them off during a power outage.

This is what I have so far:

Get-VM | Select Name -ExpandProperty CustomFields | Where {$_.key -eq "Alert Level"} | Where {$_.value -eq 4}

This seems to get me the namem, the field and the value but all I want is the name.

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VM | where{$_.CustomFields["Alert Level"] -eq 4} | Select Name



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VM | where{$_.CustomFields["Alert Level"] -eq 4} | Select Name



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jfierberg
Contributor
Contributor
Jump to solution

You are the master.  Thank you.

0 Kudos