vSphere: Get (hyperconverged) SMART information via #PowerCLI and #ESXCLI

Scooby Doo can doo-doo, but Jimmy Carter is SMARTer

Screen Shot 2016-06-13 at 13.55.55

Ok, that was weak… let’s still try to turn this blog post around to a good one and let me show you how you can be SMARTer by getting relevant SMART information out of your local disk devices within your ESXi host (Which can be really useful for vSAN / hyperconverged environments with local devices).

Thanks to Get-ESXCLI (v2) we are able to access easily the local ESXCLI tool via PowerCLI 6.3 R1++. Since there is a ESXCLI Namespace Method to access the SMART data of local disks we are going to use this in the following script.

# Change Parameter 
$vCenter = 'vcsa01.lenzker.local'
$ClusterName ='CL01'
$outputfile = 'c:\temp\smart.csv'
#codeblock
Connect-VIServer $vCenter
 
$resultList = @()
 
$Cluster = Get-Cluster -Name $ClusterName
$ESXs = $Cluster | Get-VMHost | Where {$_.ConnectionState -eq 'Connected'}
Foreach ($ESX in $ESXs){
$scsidevs = $ESX | Get-Scsilun | Where {$_.isLocal -eq $True -AND $_.canonicalName -notmatch 'mpx'}
$esxcli = $ESX | Get-ESXCLI -v2
$arguments = $esxcli.storage.core.device.smart.get.CreateArgs()
 
foreach ($scsidev in $scsidevs){
write-host "Gathering Smart-Data from $scsidev.canonicalName"
$arguments.devicename = $scsidev.canonicalName
$smart = $esxcli.storage.core.device.smart.get.Invoke($arguments)
 
$healthstatus = ($smart | Where {$_.Parameter -contains 'Health Status'}).Value
$readerror = ($smart | Where {$_.Parameter -like'Read Error Count'}).Value
$writeerror = ($smart | Where {$_.Parameter -contains 'Write Error Count'}).Value
$temperature = ($smart | Where {$_.Parameter -contains 'Drive Temperature'}).Value
 
 
$resultList += New-Object -TypeName PSCustomObject -Property @{
esx = $ESX.Name
devname = $arguments.devicename
healthstatus = $healthstatus
readerror = $readerror
writeerror = $writeerror
temperature = $temperature
} | Select esx, devname, healthstatus, readerror, writeerror, temperature
}
 
}
 
$resultfile = $resultList | export-csv -Path $outputfile -notype

et voila…it will discover all local devices and exports the relevant information into a CSV file.

get-smart output

you can find the script here.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.