Get complete ESX Host inventory from VCenter

This is a handy little script that gives you a complete list of all hosts and some pertinent information about them including Config Issues reported by VCenter.
The script saves all this information to a CSV file and emails the contents of that file in a formatted table to the email address you specify.
Let me know if there are other parameters that you think should be in here but aren’t and I will put them in here.

$from = ""
$to = @("")
$smtpserver = ""
$vcenterserver = ""

if (!(Get-PSSnapin | where {$_.Name -eq "VMware.VimAutomation.Core"}))
	Write-Verbose "Loading the VMWare snapin"
		Add-PSSnapin VMware.VimAutomation.Core -ErrorAction STOP
		#Snapin not loaded
		Write-Warning $_.Exception.Message
	Connect-VIServer $vcenterserver

$log = "$(Get-Date -format "MM-dd-yyyy").csv"

"Datacenter,Cluster,VMHost,ESXVersion,Vendor,Model,BIOSVersion,BIOSDate,CPU,Sockets,Memory(GB),NICs,ConfigIssues" > $log

foreach ($Datacenter in (Get-Datacenter)) {

    foreach ($Cluster in ($Datacenter | Get-Cluster)) {

        foreach ($VMHost in ($Cluster | Get-VMHost)) {
            $VMHostView = $VMHost | Get-View
            $ESXVersion = $VMHostView.Config.Product.FullName
            $Vendor = $VMHostView.Hardware.SystemInfo.Vendor
            $Model = $VMHostView.Hardware.SystemInfo.Model
            $BIOSVersion = $VMHostView.Hardware.BiosInfo.BiosVersion
            $BIOSdate = $VMHostView.Hardware.BiosInfo.releaseDate
            $CPUType = $VMHostView.Hardware.CpuPkg.Description | Get-Unique
            $CPUCount = $VMHostView.Hardware.CpuPkg.Count
            $MemoryGB = ($VMHostView.Hardware.MemorySize)/(1024*1024*1024) -as [int]
            $PhyNics = (($VMHost | Get-VirtualSwitch).Nic).Count
            $ConfigIssues = $VMHost.extensiondata.configissue.fullformattedmessage | Out-String -Stream
            "$Datacenter,$Cluster,$VMhost,$ESXVersion,$Vendor,$Model,$BIOSVersion,$BIOSDate,$CPUType,$CPUCount,$MemoryGB,$PhyNics,$ConfigIssues" >> $log

$head = @'</pre>
p {font-family:Calibri;
    background-color:yellow; }
body { font-family:Calibri;
       font-size:9pt; }
td, th { border:1px solid black;
         border-collapse:collapse; }
th { color:white;
     background-color:green; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }

$body=import-csv $log | convertto-html -head $head

Send-MailMessage -to $to -from $from -smtpserver $smtpserver -subject "ESX Host Info $(Get-Date -format dd/MM/yyyy)" -body "$($body)" -bodyashtml

No Comments

You can leave the first : )

Leave a Reply

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