Powershell script to Live Migrate Hyper-V Virtual Machines back to it's Preferred Owner in a Cluster.

Powershell script to Live Migrate Hyper-V Virtual Machines back to it's Preferred Owner in a Cluster.

by Stan Czerno 21. July 2011 18:15

I schedule this script to run at Startup of the Hyper-V Host to check to see if VMs have been Live Migrated to another Host.

If the VM has this Host set as being the Preferred Owner, Live Migrate them back to this Node.

I set the scheduled task as:

Security: Run whether the user is logged on or not, Run with highest privileges.
Trigger:
"At startup" and delay it for 5 minutes.
Action: "Start a program", Program/Script: powershell -command "& 'C:\scripts\movebacktopreferred.ps1'"

This script is only designed to work with a Two-Node Cluster but it is a good starting point if you have more than a Two Node Cluster. Another foreach will need to be used for the multiple nodes in the Cluster.

http://www.czerno.com/default.asp?inc=/html/windows/hyperv/cluster/HyperV_Live_Migrate_VMs_back_to_Preferred_Owner.asp

Let me know what you think about the script and if you have a better way of doing this.

Tags:

Hyper-V

Comments (2) -

Stefan
Stefan Switzerland
8/22/2011 1:50:54 AM #

greate script!

i change the static cluster-name to a variable.
--------snip----------
## Get Cluster Name
$Cluster = Get-Cluster

...
#change Hyper-V => $Cluster
$colItems = Get-ClusterOwnerNode -Cluster $Cluster -Group $VMGroup
-------/snip---------

Stan Czerno
Stan Czerno United States
8/22/2011 8:13:42 AM #

Ah, good catch...I tried to make it as generic as I could but I forgot that piece.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Category list

RecentComments

Comment RSS