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?
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
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
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"
Location | VIContainer[] | Specifies vSphere container objects (folders, datacenters, or clusters) you want to search for folders |
but it does not.
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