VMware ESX host stores good amount of information about Hardware and it sensor’s values. These values are extremely useful in troubleshooting any peformance/hardware issues. In this article, I will show you how to query these values using PowerCLI.
This function assumes that you already connected to VCenter. You need to provide list of VMhost names as parameter to this script. The script also takes optional -ExportToCSV in case you want to export the data to CSV file for further processing.
Code:
function Get-VMHostSensorsInfo { [CmdletBinding()] param( [parameter(mandatory=$true)] [string[]]$VMHostName, [switch]$ExportToCSV ) $OutArr = @() foreach($VMHost in $VMHostName) { Write-Verbose "Fetching data from $VMHost" try { $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 $OutArr += $object } } catch { $object = New-Object -TypeName PSObject -Property @{ VMHost = $VMHost SensorName = "NA" Status = "FailedToQuery" CurrentReading = "FailedToQuery" } | Select-Object VMHost, SensorName, CurrentReading, Status $OutArr += $object } } if($ExportToCSV) { Write-Verbose "Exporting to c:\temp\sensorsinfo.csv" $OutArr | export-csv c:\temp\sensorsinfo.csv -NoTypeInformation } else { return $OutArr } }
Usage:
Using this code is very simple. First open your PowerCLI and connect the VCenter using the credentials that can query the host information. Then copy and paste the above function to the PowerCLI shell and start running commands below as per your needs.
Get Sensors status of single host
Get-VMHostSensorsInfo -VMHostName server1
Get sensors status of multiple hosts
Get-VMHostSensorsInfo -VMHostName server1, server2
Get sensors status of hosts from file
Get-VMHostSensorsInfo -VMHostName (Get-Content c:\temp\servers.txt)
Export sensors status to CSV
Get-VMHostSensorsInfo -VMHostName (Get-Content c:\temp\servers.txt) -ExportToCSV
Hope this helps…