PowerCli监控Esxi硬件状态

 

#在CentOS上安装powershell-lts-7.0.1-1.rhel.7.x86_64.rpm
#然后将VMware-PowerCLI-12.4.1-18769701.zip解压后拷贝到/opt/microsoft/powershell/7-lts/Modules/目录下

Connect-VIServer -Server $VMHost -username $UserName -Password $PassWord
$VMHostObj = Get-VMHost -Name $VMHost -EA Stop | Get-View
$sensors = $VMHostObj.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo
foreach($sensor in $sensors)
    {
    $object = New-Object -TypeName PSObject -Property @{
        VMHost = $VMHost
        SensorName = $sensor.Name
        Status = $sensor.HealthState.Key
        CurrentReading = $sensor.CurrentReading 
    } #| Select-Object VMHost, SensorName, CurrentReading, Status
    if ($object.Status -ne "Green")
        {
        $Subject = "Esxi($VMHost)硬件告警"
        $Body = $object.SensorName + " 当前状态为 " + $object.Status + " ,当前值为 " + $object.CurrentReading + ""
        if ($object.SensorName -ne "System Board 1 Power Optimized 0")
            { Sendmail $SystemMailAdmin $Subject $Body }
        }
    }
DisConnect-VIServer -Server $VMHost  -Confirm:$false

 

posted on 2024-05-21 15:30  momingliu11  阅读(45)  评论(0编辑  收藏  举报