Close Menu
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn X (Twitter) Facebook
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn Facebook X (Twitter)
PowerShell.roPowerShell.ro
Home»Powershell»Get HA events of VM restart from vCenter
Powershell

Get HA events of VM restart from vCenter

Catalin CristescuBy Catalin CristescuSeptember 14, 2023
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email

When the High Availability (HA) feature is active within your vCenter cluster, it provides an automated solution for handling host failures by seamlessly restarting VMs on alternative ESXi hosts within the same cluster.

This process generates a detailed event log documenting each restart, and you have the option to utilize a PowerCLI script to extract a comprehensive list of the restarted VMs.

Despite searching online for scripts that perform this VM list retrieval task, I was unable to locate a suitable solution. Consequently, I took matters into my own hands and developed a custom script for this purpose. While numerous blog posts contain cmdlets for retrieving VM restart events, they does not include the listing of the specific VMs affected by these events.

Script

# HA VM reset day(s) number
$HAVMresetold = 1
# HA VM restart day(s) number
$HAVMrestartold = (Get-Date).AddDays(-2)

$Date = Get-Date
Write-Host "..Checking HA VM restart"
$HAVMrestartlist = @(Get-VIEvent -MaxSamples 100000 -Start $HAVMrestartold -Type Warning | Where {$_.FullFormattedMessage -match "restarted"} | select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending)
If (($HAVMrestartlist | Measure-Object).count -gt 0) {

                $regexPattern = "virtual machine (\w+) on host"
                $matches = [Regex]::Matches($HAVMrestartlist.FullFormattedMessage, $regexPattern)
                
                $output = @()
                foreach ($match in $matches) {
                    $serverName = $match.Groups[1].Value
                    Write-Host "Server Name: $serverName"

                    $property = @{"Server" = $serverName}
                    $output += New-Object -TypeName psobject -Property $property
      }	
}
$output
HA High Availability vm restart vmware
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleAutomate your ILO configuration using HPE iLO Cmdlets
Next Article Get HA events of Host restart from vCenter
Catalin Cristescu
  • Website

Related Posts

Automation

PowerShell script for automated remediation for CrowdStrike issue

July 20, 2024
VMWare

vExperts stats 2024

May 27, 2024
Automation

Tagging Virtual Machines with the CISTag Module in PowerShell

February 1, 2024

1 Comment

  1. Pingback: Get HA events of Host restart from vCenter – PowerShell.ro

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
Categories
  • Automation (11)
  • Powershell (14)
  • Uncategorized (1)
  • VMWare (15)
  • Windows (2)
About Powershell.ro

Powershell.ro, the ultimate hub for tech enthusiasts! Dive into expert-written articles on PowerShell scripts, VMware, automation, Microsoft technologies, and DevOps practices. Unlock tips, tutorials, and solutions designed to empower IT professionals and boost your skills in automation and infrastructure management.

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
LinkedIn
© 2025 PowerShell.ro.

Type above and press Enter to search. Press Esc to cancel.