VMware Cloud Community
aymericcarraro
Contributor
Contributor

PowerOn VM with powercli when host is disconnected and DRS is activated

Hi guys, 

I've a short question regarding powerCLI in case of DR test. 

I try to automate the powerOn of some VMs based on priority to start applications in the right order.

During DR test, some ESXi servers are shut down with the VM on them. Then we want to restart them on the secondary site (Active/active storage underneath).

When I start the VM using VCenter interface, DRS will de-register then register the VM on a surviving host, I'm quite happy with that. 

BUT, when I execute the Start-VM cmdlet on a VM that where running on a host that is now marked as disconnected (and the VM has also the disconnected flag) I've an error syaing that the host is not available and therefore the cmdlet cannot start the VM. 

Do you know if there is another cmdlet available or another way to start VM only on connected hosts? and then let DRS do the job as using the VCenter interface. Or I've to automate the unregister / register stuff? 

 

Thanks beforehand. 

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Try if this does the trick.

It will try to power on the VM, then check the DRS recommendations, and then apply the recommendation.

It's the recommendation that should tell on which ESXi node the VM shall be restarted.

$vmName = 'TestVM'

$vm = Get-VM -Name $vmName

$dc = Get-Datacenter -VM $vm

$cluster = Get-Cluster -VM $vm

$option = New-Object VMware.Vim.

$dc.ExtensionData.PowerOnMultiVM($vm.ExtensionData.MoRef,$null)

$cluster.ExtensionData.UpdateViewData()

$cluster.ExtensionData.Recommendation | %{

    $cluster.ExtensionData.ApplyRecommendation($_.Key)

}


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

Reply
0 Kudos