Welcome to TechNet Blogs Sign in | Join | Help

Off Campus

Michael Greene - DataCenter TSP - US Education

News

  • The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

    Subscribe as Email

    My TechNet Edge Profile

    Blue Monster

Evacuate! script – move all VMs off cluster node using intelligent placement

Just wanted to share this script I wrote.  The idea is I want to do something (anything) to a host and feel it might cause a service interruption so I would prefer to move all VMs off the node.  Rather than doing it manually in the cluster or in VMM, or forcing VMs off in a reboot, this script will get a list of all VMs on a node and use intelligent placement to fail over VMs to the best possible node in your cluster in one quick operation.  This should work for VMs running on either Hyper-V or VMWare as long as you have SCVMM managing your environments.

   1: # ------------------------------------------------------------------------------ 
   2: # EVACUATE! 
   3: # ------------------------------------------------------------------------------ 
   4: # blogs.technet.com/offcampus 
   5: # version 1.0 
   6: # 
   7: # Description 
   8: #  Useful for quickly moving all VMs off a host using intelligent placement. 
   9: # 
  10: # ------------------------------------------------------------------------------ 
  11:  
  12: $vmhost=get-vmhost 
  13: write-host "Hosts:" -foregroundcolor "green" 
  14: foreach ($hostname in $vmhost){write-host $hostname.computername -foregroundcolor "green"} 
  15: write-host "" 
  16:  
  17: $Name = Read-Host "Which host would you like to evacuate?" 
  18:  
  19: $VMMServer = get-vmmserver -computername "v-scvmm-01.usedu.int" 
  20: $VMArray = get-vm -vmhost $Name | where {$_.customproperties -notcontains "Local"} 
  21: @( ForEach ($VM in $VMArray) { 
  22:     $VMHostRating = get-vmhostrating -vm $VM -vmhostgroup "All Hosts" -ismigration | sort -property rating -descending 
  23:     move-vm -vm $VM -vmhost $VMHostRating[0].name -RunAsynchronously 
  24: })
Posted: Monday, March 09, 2009 7:00 AM by michael.greene

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker