Hi,
could anyone help me write a script for doing a simple task?
I would like the scipt to:
Shutdown Machine A
Check when Machine A is powered off, then power on Machine B
Thanks
don't use stop-vm -kill. because of this HA is restarting first VM.
Use shutdown-VMGuest command to shutdown Guest OS of VM, this will need VM tools to be running.
Also you need to wait for couple of minutes before you for next command because, Shutdown of First VM will take some time.
hi,
You can check this script, it works in my environment.
Connect-VIServer <YourvCenter>
$GetPower= Get-VM <vmA>
if ($GetPower.powerstate -eq "PoweredOn") {
Get-VM <vmA> | Where-Object {$_.PowerState -eq "PoweredOn"} | Stop-VM -kill -confirm:$false
Get-VM <vmB> | Start-VM
}
else {
Get-VM <vmB> | Start-VM
}
Regards,
Thanks for the script.
It almost works perfectly, however:
It shuts down "testvm"
starts up "testvm2"
and starts up "testvm" right afterwards.
$GetPower= Get-VM testvm
if ($GetPower.powerstate -eq "PoweredOn") {
Get-VM testvm | Where-Object {$_.PowerState -eq "PoweredOn"} | Stop-VM -kill -confirm:$false
Get-VM testvm2 | Start-VM
}
else {
Get-VM testvm2 | Start-VM
From the events log on "testvm", it says that vSphere HA restarted the virtual machine...not sure why it does this?
any tips?
don't use stop-vm -kill. because of this HA is restarting first VM.
Use shutdown-VMGuest command to shutdown Guest OS of VM, this will need VM tools to be running.
Also you need to wait for couple of minutes before you for next command because, Shutdown of First VM will take some time.
Or change your settings for this VM in your cluster HA "Virtual Machine Options" set "Disable".
Do not change setting for your Cluster.
Regards,