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?
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
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
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...
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
When I run the command it returns an error:
You must provide a value expression on the right-hand side of the '-eq' operator.
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
Thank you for the help.