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»Automation»Get HA events of Host restart from vCenter
Automation

Get HA events of Host restart from vCenter

Catalin CristescuBy Catalin CristescuOctober 11, 2023
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email

Part II of this post Get HA events of VM restart from vCenter – PowerShell.ro

In part I of getting the HA events we have searched for the VM restart events. Now, I wanted to search for the HA events of Host restart and add it to an object, using this Powershell object later for other scope.

In this blog post, we’ll explore a PowerShell script designed to monitor Host Availability (HA) events in a VMware environment. The script focuses on detecting instances where a HA host has failed and provides information about the host.

Script Breakdown

  1. Configuration Settings:
    • $HAHostrestart: A boolean flag indicating whether to check for HA host restarts.
    • $maxevents: Maximum number of events to retrieve.
    • $searchperiod: Number of days to search for HA events.
    • $stopevents and $startevents: Define the time range for event retrieval.
  2. Checking HA Host Restart:
    • The script begins by checking if the HA host restart check is enabled ($HAHostrestart is set to $true).
    • If enabled, it fetches the relevant HA events within the specified time range using Get-VIEvent.
  3. Processing HA Host Events:
    • If there are events, the script filters them to include only events related to HA host failures.
    • Extracted host names are processed to obtain server names and fully qualified domain names (FQDNs).
    • A custom object is created for each host, containing the server name and FQDN.
  4. Output:
    • The server names of affected hosts are then displayed.

Conclusion

This PowerShell script offers a streamlined way to monitor HA host restarts in a VMware environment. By leveraging the VMware PowerCLI module, users can easily customize and integrate this script into their infrastructure monitoring solutions.

Monitoring HA events is crucial for maintaining the reliability and availability of virtualized environments. This script provides a foundation for building more comprehensive monitoring and alerting systems tailored to specific organizational needs.

Feel free to adapt and expand upon this script to suit your environment, and stay tuned for more PowerShell insights!

Script

# HA VM restart log

$HAHostrestart = $true
$maxevents = 250000
$searchperiod = 1
$stopevents = Get-Date
$startevents = $stopevents - (New-TimeSpan -Days $searchperiod)

# Get Host HA events
if ($HAHostrestart) {
    Write-Host "..Checking HA Host restart"
    
    $HAHostrestartlist = Get-VIEvent -Start $startevents -Finish $stopevents -MaxSamples $maxevents | Where-Object { $_.EventTypeID -eq "com.vmware.vc.HA.DasHostFailedEvent" }

    if ($HAHostrestartlist.Count -gt 0) {
        $vmHosts = $HAHostrestartlist | Where-Object { $_.EventTypeId -eq "com.vmware.vc.HA.DasHostFailedEvent" } | Select-Object ObjectName -ExpandProperty ObjectName

        $outputHost = foreach ($matchhost in $vmHosts) {
            $matchhostname = $matchhost.Split(".")[0]
            [PSCustomObject]@{
                Server = $matchhostname
                FQDN = $matchhost
            }
        }

        $outputHost.Server
    }
}

Event Monitoring HA (High Availability) Infrastructure Monitoring powercli powershell scripting vmware
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleGet HA events of VM restart from vCenter
Next Article Simplify Your Day-to-Day Tasks with These 5 Essential PowerShell Scripts
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

Comments are closed.

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.