VMware Cloud Community
eaphilipp
Contributor
Contributor

Get a list of VMs but exclude templates

I am looking for some guidance, I am not sure how to tackle this, I want to get a list of all my VMs in one of my vCenters but I want to exclude the templates from that list. Can anyone help point me in the right direction?

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

The Get-VM cmdlet does not return Templates.

If you are using Get-View, you can use the Filter parameter

Get-View -ViewType VirtualMachine -Filter @{'Config.Template' = 'false'} |
Select Name


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

eaphilipp
Contributor
Contributor

Duh... Yes you're right and I am an idiot. To that line can I add, get powered off VMs only?

Reply
0 Kudos
LucD
Leadership
Leadership

Sure, you can multiple conditions to the filter.
Just note that it is an AND between all these conditions.

Get-View -ViewType VirtualMachine -Filter @{'Config.Template' = 'false';'Runtime.PowerState' = 'poweredOff'} |
Select Name


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