# 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.

$computerlist=@'
hyperVServer1
hyperVServer2
hyperVServer100
'@
$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
    #$vmNames=(get-vm).Name
    #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
      try{        
        $vm|resume-vm -ea stop
        write-host ": resumed" -foregroundcolor Green
      }catch{
        write-warning $_
        continue
      }    
    }   
  }
}