We recently noticed some hosts in our environment that show an alert triggered by ‘Status of other host hardware objects’. Upon further investigation it turned out that this was caused by the system event log (SEL) that is about to run out of space.

Now if you don’t mind not having a bit of history of your hardware-related events you can easily clear it and there’s even a function in vCenter that lets you do that. However it turns out that – at least in vCenter 6.7 U2 – the reset function doesn’t actually perform a reset but a refresh instead.

Using the code capture shows this behavior. And this clearly NOT what we intended.

Luckily the vSphere Web Services API documentation clearly shows that there’s a ClearSystemEventLog method. So what’s to stop us from writing a simple PowerCLI function? Well……. actually nothing.

function Clear-VMHostSEL {
  Param(
    [parameter(Mandatory=$true, ValueFromPipeline=$true)]$VMHosts
  )
  process {
    foreach($VMHost in $VMHosts){
      $VMhostView = Get-View $VMHost
      Write-Host "Clearing System Event Log Of: $VMHost"
      $VMhostHealthView = Get-View -Id $VMhostView.ConfigManager.HealthStatusSystem
      $VMhostHealthView.ClearSystemEventLog()
    }
  }
 }

Once you enter this function in a powershell session and log on to your vCenter you can pass a list of ESXi hosts to this function with Get-VMHost and it will clear the system event log. Just like this.

Get-VMhost -Name SomeHost | Clear-VMHostSEL

Enjoy!


Rudolf Kleijwegt

I am an experienced IT professional with over 20 years of hands-on experience designing, deploying, and maintaining IT infrastructure in both enterprise and service provider environments. My skills span across Linux and Windows and a multitude of server applications, allowing me to excel in a wide range of IT roles. Currently, my primary focus is on Software Defined DataCenter and DevOps. I am passionate about staying up to date with the latest trends in the industry to achieve superior outcomes.

3 Comments

Daniel Andryszak · July 5, 2022 at 5:27 pm

Nice function.

BTW – “Using the code capture shows this behavior. And this clearly NOT what we intended.”

What are you using to capture code?

Ram · December 8, 2022 at 3:51 pm

In the function call why are we passing ‘-Name SomeHost’ ? By default, Get-VMhost return all the hosts, the same is piped to the function and the loop inside would take care of each hosts right?

Leave a Reply

Avatar placeholder

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