Automation

 View Only
  • 1.  Get a list of VMs but exclude templates

    Posted Nov 03, 2022 01:15 PM

    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?



  • 2.  RE: Get a list of VMs but exclude templates

    Posted Nov 03, 2022 01:28 PM

    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


  • 3.  RE: Get a list of VMs but exclude templates

    Posted Nov 03, 2022 01:36 PM

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



  • 4.  RE: Get a list of VMs but exclude templates

    Posted Nov 03, 2022 02:08 PM

    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