I recently had a problem where VMware was reporting a memory module failure for all of our UCS blades. After working with Cisco and VMware we came to the conclusion that the alerts were false and were caused SEL logs being full on the hosts. To clear these logs VMware support requested that I run “localcli hardware ipmi sel clear” on every host and then reset the management agents. I have about 100 hosts that needed this done so going one by one was not something I wanted to do. PowerCLI to the rescue!
You will need the latest PowerCLI installed for this to run as is. PowerCLI changed to module based in the latest versions. You will also need to install Posh-SSH from the PowerShell Gallery. If unsure how to do that, consult the manual (google)!
#Script to clear the SEL logs of each host in a cluster.
#Requires Posh-ssh to be installed from the powershell gallery
#Requires Latest PowerCLI to be installed (Module based, not snapin based)
Import-Module -Name VMware.VimAutomation.Core
Connect-VIServer vcenter
$cluster = "ClusterName"
$esxilogin = Get-Credential -Credential "root"
$esx_all = Get-Cluster $cluster| Get-VMHost
foreach ($esx in $esx_all){
$sshService = Get-VmHostService -VMHost $esx.Name | Where { $_.Key -eq “TSM-SSH”}
Start-VMHostService -HostService $sshService -Confirm:$false
# Connect with ssh and execute the commands
New-SSHSession -ComputerName $esx.Name -AcceptKey -Credential $esxilogin
Invoke-SSHCommand -SessionId 0 -Command "localcli hardware ipmi sel clear; nohup /sbin/services.sh restart > foo.out 2> foo.err < /dev/null &"
#pause to allow management agents to fire back up
Start-Sleep -Seconds 75
Remove-SSHSession -SessionId 0
Stop-VMHostService -HostService $sshService -Confirm:$false
}