Display all ESXi Logs with ESXi Log Generator

IT PROJECTS

10/25/20222 min read

Display all ESXi logs from a host using PowerCLI, filter by category and export support bundles using this unofficial Powershell script.

ESXi Log Generator

# By: Brady Keezer

Write-host "Ensure you copy this script to your local machine before use."

#Connect to a vCenter Instance

Connect-VIServer -Server '<vCenter Server Name>' -User *

#Adds snapin for ability to create forms

Add-type -AssemblyName system.windows.forms

[System.Windows.Forms.Application]::EnableVisualStyles()

$forms = 'system.windows.forms.form'

$button = 'system.windows.forms.button'

$sysdrawpoint = 'system.drawing.point'

$initialdir = 'C:\'

#Background form and title

$trackerfileupload = New-Object -TypeName $forms

$trackerfileupload.clientsize = '800,375'

$trackerfileupload.text = 'ESXi Log Generator'

$trackerfileupload.topmost = $false

#Just a label on form not a button

$servername = New-Object -TypeName System.Windows.Forms.Label

$servername.Text = '<server name>'

$servername.AutoSize = $true

$servername.Width = 25

$servername.Height = 10

$servername.Location = New-Object -TypeName $sysdrawpoint -ArgumentList (20,10)

#Button to List VMs

$ListVMsVX01 = New-Object -TypeName $button

$ListVMsVX01.backcolor = '#1a80b6'

$ListVMsVX01.text = 'List VMs'

$ListVMsVX01.width = 96

$ListVMsVX01.height = 35

$ListVMsVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (691,0)

$ListVMsVX01.forecolor = '#ffffff'

#Button to Export vCenter Bundle

$vCenterBundleVX01 = New-Object -TypeName $button

$vCenterBundleVX01.backcolor = '#1a80b6'

$vCenterBundleVX01.text = 'Export vCenter Support Bundle'

$vCenterBundleVX01.width = 96

$vCenterBundleVX01.height = 35

$vCenterBundleVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (591,0)

$vCenterBundleVX01.forecolor = '#ffffff'

#Button to Export ESXi Bundle

$ESXiBundleVX01 = New-Object -TypeName $button

$ESXiBundleVX01.backcolor = '#1a80b6'

$ESXiBundleVX01.text = 'Export ESXi Support Bundle'

$ESXiBundleVX01.width = 96

$ESXiBundleVX01.height = 35

$ESXiBundleVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (491,0)

$ESXiBundleVX01.forecolor = '#ffffff'

#Button to VPXA

$VPXAVX01 = New-Object -TypeName $button

$VPXAVX01.backcolor = '#1a80b6'

$VPXAVX01.text = 'VPXA'

$VPXAVX01.width = 96

$VPXAVX01.height = 35

$VPXAVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (391,0)

$VPXAVX01.forecolor = '#ffffff'

#Button to FDM

$FDMVX01 = New-Object -TypeName $button

$FDMVX01.backcolor = '#1a80b6'

$FDMVX01.text = 'FDM'

$FDMVX01.width = 96

$FDMVX01.height = 35

$FDMVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (291,0)

$FDMVX01.forecolor = '#ffffff'

#Button to Hostd

$HostdVX01 = New-Object -TypeName $button

$HostdVX01.backcolor = '#1a80b6'

$HostdVX01.text = 'Hostd'

$HostdVX01.width = 96

$HostdVX01.height = 35

$HostdVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (191,0)

$HostdVX01.forecolor = '#ffffff'

#Button to Vmkernel

$VmkernelVX01 = New-Object -TypeName $button

$VmkernelVX01.backcolor = '#1a80b6'

$VmkernelVX01.text = 'Vmkernel'

$VmkernelVX01.width = 96

$VmkernelVX01.height = 35

$VmkernelVX01.location = New-Object -TypeName $sysdrawpoint -ArgumentList (91,0)

$VmkernelVX01.forecolor = '#ffffff'

################################################################################

#Adding texbox, buttons to forms to display

$trackerfileupload.controls.AddRange(@($servername, $HostdVX01, $FDMVX01, $VmkernelVX01, $VPXAVX01, $ESXiBundleVX01, $vCenterBundleVX01, $ListVMsVX01))

################################################################################

#######################

#Vmkernel Button

#######################

$VmkernelVX01.Add_Click({

get-log -VMHost <server name>.MY.DOMAIN.COM -Key vmkernel | select -ExpandProperty entries | Where-Object -FilterScript {$_ -like "*"} | Out-GridView

})

#######################

#Hostd Button

#######################

$HostdVX01.Add_Click({

get-log -VMHost <server name>.MY.DOMAIN.COM -Key hostd | select -ExpandProperty entries | Where-Object -FilterScript {$_ -like "*"} | Out-GridView

})

#######################

#FDM Button

#######################

$FDMVX01.Add_Click({

get-log -VMHost <server name>.MY.DOMAIN.COM -Key fdm | select -ExpandProperty entries | Where-Object -FilterScript {$_ -like "*"} | Out-GridView

})

#######################

#VPXA Button

#######################

$VPXAVX01.Add_Click({

get-log -VMHost <server name>.MY.DOMAIN.COM -Key vpxa | select -ExpandProperty entries | Where-Object -FilterScript {$_ -like "*"} | Out-GridView

})

#######################

#ESXi Bundle Button

#######################

$ESXiBundleVX01.Add_Click({

$destpath = Read-Host "Enter Destination Path"

Get-VMhost <server name>.MY.DOMAIN.COM | Get-log -Bundle -DestinationPath $destpath

})

#######################

#vCenter Bundle Button

#######################

$vCenterBundleVX01.Add_Click({

$destpath = Read-Host "Enter Destination Path"

Get-log -Bundle -DestinationPath $destpath

})

#######################

#List VMs Button

#######################

$ListVMsVX01.Add_Click({

Get-VM | Select-Object Name, PowerState, Guest, VMHost | Sort-Object -Property VMHost | Out-GridView

})

$null = $trackerfileupload.ShowDialog()

Related Stories