VMware Cloud Community
fornax
Contributor
Contributor
Jump to solution

Finding all VMs in a specific cluster AND folder

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?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cluster = Get-Cluster -Name MyCluster

$folder = Get-Folder -Name MyFolder

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


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cluster = Get-Cluster -Name MyCluster

$folder = Get-Folder -Name MyFolder

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


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

ivanerben
Enthusiast
Enthusiast
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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).


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

0 Kudos