Resume All Guest VMs in a Clustered Hyper-V Environment

# resumeAllVms.ps1
# Significance: this script is useful in a Clustered Hyper-V environment
# where storage was down for over 60 seconds, causing Hyper-V to put all guest VM's into 'paused-critical' statuses.
# During such event, the cluster would be unreachable as well. Hence, knowing node names prior to pasting this script
# would be necessary.

$computernames=@($computerlist -split "`n")|%{$_.Trim()}
foreach ($computername in $computernames){
  invoke-command $computername {
    write-host "Connected to $env:computername..."
    #Get list of all VMs on this host
    #write-host "$env:computername`:`r`n$($vmNames|out-string)"
    # Unpausing all VMs
    $pausedVms=get-vm | where state -eq 'paused'
    foreach($vm in $pausedVMs){        
        write-host $vm.Name -nonewline
        $vm|resume-vm -ea stop
        write-host ": resumed" -foregroundcolor Green
        write-warning $_

Leave a Reply

Your email address will not be published. Required fields are marked *