jfierberg
Contributor
Contributor

powercli script retrieve vmname based on custom field value

Jump to solution

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

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

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
jfierberg
Contributor
Contributor

You are the master.  Thank you.

0 Kudos