PowerCLI

 View Only
  • 1.  Finding all VMs in a specific cluster AND folder

    Posted May 10, 2018 08:34 PM

    I'm following this document to upgrade Guest Tools on all my Windows guests after host upgrades, and I want to use the PowerCLI method. The example selects all VMs starting with "prod-":

    Get-VM prod-* | ...

    I can get all VMs in a specific cluster with:

    Get-Cluster clustername | Get-VM | ...

    I can get all VMs in a specific folder with:

    Get-Folder foldername | Get-VM | ...

    What I want is all VMs that are in a specific cluster AND a specific folder, but attempting any combination of the above throws errors. I'm new to PowerCLI/PowerShell... the solution could be glaringly obvious. Can I get a list of all VMs in a specific cluster/folder combination?



  • 2.  RE: Finding all VMs in a specific cluster AND folder
    Best Answer

    Posted May 10, 2018 09:26 PM

    Try something like this

    $cluster = Get-Cluster -Name MyCluster

    $folder = Get-Folder -Name MyFolder

    Get-VM -Location $cluster | where{(Get-VM -Location $folder) -contains $_}



  • 3.  RE: Finding all VMs in a specific cluster AND folder

    Posted Jan 28, 2019 04:34 PM

    Thanks, it works this way! It is only slow as hell. I need it to run just few times, so whatever. It is just sad, that according to docs Get-Folder should work with -Location "cluster-name"

    LocationVIContainer[]Specifies vSphere container objects (folders, datacenters, or clusters) you want to search for folders

    but it does not.



  • 4.  RE: Finding all VMs in a specific cluster AND folder

    Posted Jan 28, 2019 05:57 PM

    I think we are dealing with a documentation error here.
    If you look under the VMs and Templates tab in the Web Client, clusters are not in there at all.
    Folders of type VM are located under the datacenter (or another VM folder).