VMware Cloud Community
Prospy31
Contributor
Contributor
Jump to solution

How to create a vm on a DRS Cluster ?

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.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
johnlennon
Enthusiast
Enthusiast
Jump to solution

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

admin
Immortal
Immortal
Jump to solution

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.

0 Kudos
hugopeeters
Hot Shot
Hot Shot
Jump to solution

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.

0 Kudos
admin
Immortal
Immortal
Jump to solution

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.

0 Kudos