VMware Cloud Community
Lax617
Contributor
Contributor
Jump to solution

Modify PowerCLI Script to use DRS and Storage DRS

Hello,

I have a PowerCLI script that specifies a host and datastore to create a new virtual machine on, which has served us well. Now we have enabled DRS and Storage DRS and I am wondering what needs to change in order to take advantage of these features. Are there commands to specify a cluster and datastore cluster and let DRS decide initial placement for a new VM? Right now we set all of the hosts and datastores as variables and use them in the line below.

Thanks.

$newVM = New-VM -Name $NewVMname -VM $TemplateName -Datastore $datastore -VMHost $vHost -Confirm:$false -Location $myName

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you define a Datastorecluster ?

If yes, then you can replace the Datastore parameter value with the datastorecluster object.

Replacing a VMHost with a cluster is not supported I'm afraid.

But you can use something like this

New-VM -Name TestVM -Datastore DSC -ResourcePool (Get-Cluster -Name MyCluster | Get-Resourcepool -Name Resources)

This will automatically select the VMHost.

The VM will appear in the root of the cluster.

DSC is the name of a datastorecluster in cluster MyCluster


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Did you define a Datastorecluster ?

If yes, then you can replace the Datastore parameter value with the datastorecluster object.

Replacing a VMHost with a cluster is not supported I'm afraid.

But you can use something like this

New-VM -Name TestVM -Datastore DSC -ResourcePool (Get-Cluster -Name MyCluster | Get-Resourcepool -Name Resources)

This will automatically select the VMHost.

The VM will appear in the root of the cluster.

DSC is the name of a datastorecluster in cluster MyCluster


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

0 Kudos
Lax617
Contributor
Contributor
Jump to solution

Thanks Luc,

So yes we actually have a datastore cluster. Thinking about it some more I suppose specifying the host isn't really an issue, since DRS will decide initial placement at power up anyway.

BTW I loved your blog post about scripting DVS configurations. That is great stuff.

0 Kudos