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: })