Posted On January 25, 2023

Resume All Guest VMs in a Clustered Hyper-V Environment

kimconnect 0 comments
blog.KimConnect.com >> Virtualization , Windows >> 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.

$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
      }    
    }   
  }
}

Leave a Reply

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

Related Post

List Autorun Services

# $cred = get-Credential -credential kdoan-a $Username = 'kimconnect\kim-Admin $Password = 'PASSWORD' $pass = ConvertTo-SecureString…

How To Change Default Backup Directory of Microsoft SQL Server

Option 1: Use the GUI Run Ssms.exe > login as sa > Right-click SQL Server…

Common Windows Maintenance using PowerShell

# Install Windows Features:Install-WindowsFeature SNMP-Service -IncludeManagementToolsInstall-WindowsFeature -name Telnet-Client Install-Module Posh-SSH -Force# Disable Service:sc config "SERVICE_NAME"…