ESXi Host Versions – PowerCli

Okay, so I would admit that I’m not the best with PowerCli but recently we had a request to produce a list of all of the ESXi hosts we have on a vCenter along with their Version and build number.

Now this can be done easily on an individual basis by logging onto each host and running the command:

vmware -vl

This will produce a result similar to below:



Unfortunately performing this command on a number of hosts could be time consuming.  I therefore went ahead and produced the following PowerCli script that would collect it for a number of hosts on a vCenter… as previously explained, there may be a better way to perform this in PowerCli but this solution worked for me:

Connect-VIServer -Server vCenterName

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

$smtpServer = "smtpservername"
$smtpFrom = "VMware Build Versions <senderemailaddress>"
$smtpTo = "destinationemailaddress"
$messageSubject = "VMware Build Versions - $(Get-Date)"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true 

$dts = @(
get-view -ViewType HostSystem -Property Name, Config.Product | select Name,@{ expression={$_.Config.Product.Version}; label='Version' },@{ expression={$_.Config.Product.Build}; label='Build Number' }
$message.Body = $dts | ConvertTo-HTML -Head $style

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)

This should produce an email with a table similar to below:

Leave a Reply

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