It's easy to create a VM on a specific host :
$vmhost = get-vmhost MyESX
$vm = new-vm -host $vmhost -name MyNewVM
But I can't create a VM on a specific cluster DRS. I tried
$vmhost = get-vmhost -Location MyDRSCluster
$vm = new-vm -host $vmhost -name MyNewVM
But it doesn't work.
So please, how to create a vm directly on a DRS Cluster like you do with a right click on a cluster name in the Virtual Center ?
Thanks in advance.
Jean-Louis.
If you create a new guest in the VI Client from a cluster you will notice that the guest is still created for a specific host.
The host is one of the nodes of the cluster.
I don't know the VMHost allocation schema in the VI Client when you create guests under a cluster but I suspect it is always the first node.
So it looks "normal" to me that there is no "cluster" option in the New-VM.
You could get the nodes for a cluster and the create your new guest on one of these.
Something like this for example:
$clus = Get-View (Get-Cluster -Name <cluster-name>).ID $esx = Get-VMHost -Name (get-view $clus.Host[0]).Name New-VM -Name <guest-name> -VMHost $esx
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you create a new guest in the VI Client from a cluster you will notice that the guest is still created for a specific host.
The host is one of the nodes of the cluster.
I don't know the VMHost allocation schema in the VI Client when you create guests under a cluster but I suspect it is always the first node.
So it looks "normal" to me that there is no "cluster" option in the New-VM.
You could get the nodes for a cluster and the create your new guest on one of these.
Something like this for example:
$clus = Get-View (Get-Cluster -Name <cluster-name>).ID $esx = Get-VMHost -Name (get-view $clus.Host[0]).Name New-VM -Name <guest-name> -VMHost $esx
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What LucD says is correct, I have a script that goes a bit further by setting some variables and then creating the VM in the DRS and datastore I specified:
New-VM -Name $NewVMName -Host (Get-VMHost -Datastore $datastore)[0] -GuestId $VMGuestOS -Datastore $datastore -MemoryMB $RAM -Floppy -CD -DiskMB $disk -ResourcePool $respool -Location $folder
Message was edited by: halr9000 / fixed formatting
I wanted to mention that you don't have to bother with views for enumerating hosts in clusters, you can just say
get-cluster X | get-vmhost
, this will return a list of them, and any member of the list can be piped into new-vm.
It's a shame though, because in this way, you do not use the "initial placement recommendation" DRS can provide when using the GUI.
Same goes for the Move-VM cmdlet, which allows one to specify a VIContainer object as a destination. I expected it would accept a cluster object, but it doesn't.
It's a shame though, because in this way, you do not use the "initial placement recommendation" DRS can provide when using the GUI.
Same goes for the Move-VM cmdlet, which allows one to specify a VIContainer object as a destination. I expected it would accept a cluster object, but it doesn't.
Good point, noted. We'll see when we can add DRS recommendations.