VMware Cloud Community
regierd
Contributor
Contributor
Jump to solution

get-vm from cluster and folder

I am trying to write a script that will get all vms from a certain folder and only on certain clusters. I have tried

get-cluster -name cluster1 | get-folder -name folder1 | get-vm

But it does not seem to work properly.

How can I get a list of all VMs that are running in a particular folder and only on one of our clusters?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You did replace the placeholders <folder-name> and <cluster-name> with strings that hold the actual foldername and clustername for your environment ?

Suppose you're looking for a folder called "Production" in a cluster called "MyCluster", then the statement would be

Get-Folder -Name "MyCluster" | Get-VM | where {($_ | Get-Cluster).Name -eq "Production"}


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

There are 2 types of folders in a VI environment, the so-called yellow and blue folders.

The yellow folders exist in the Hosts & Clusters view.

The blue folders exist in the Virtual Machines & Templates view.

But you can't create yellow folders under a cluster and you can't have clusters under a blue folder.

So I'm not sure what exactly you are trying to do.

Perhaps you could give a bit more information ?


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

0 Kudos
regierd
Contributor
Contributor
Jump to solution

We have 4 clusters of ESX hosts in our VirtualCenter. These clusters all run some production and some test VMs. We then have Blue folders setup for production and test. I want to get a list of all production VMs that are only in a certain cluster.

Hope that helps a little...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I think I got it.

Try this

 Get-Folder -Name <folder-name> | Get-VM | where {($_ | Get-Cluster).Name -eq <cluster-name>}


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

0 Kudos
regierd
Contributor
Contributor
Jump to solution

When I run the command it returns an error:

You must provide a value expression on the right-hand side of the '-eq' operator.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You did replace the placeholders <folder-name> and <cluster-name> with strings that hold the actual foldername and clustername for your environment ?

Suppose you're looking for a folder called "Production" in a cluster called "MyCluster", then the statement would be

Get-Folder -Name "MyCluster" | Get-VM | where {($_ | Get-Cluster).Name -eq "Production"}


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

0 Kudos
regierd
Contributor
Contributor
Jump to solution

Thank you for the help.

0 Kudos