PowerCLI script to capture ESXTOP from all the Hosts in the vCenter server for 5 mins

  • Post category:Power CLI / VMware
  • Post last modified:July 26, 2024

Please find the PowerCLI script to capture ESXTOP from all ESXi Host in the vCenter Server for 5 Mins.

 

# Connect to the vCenter Server
$vcServer = "vcenter-server.example.com"
$vcUsername = "username"
$vcPassword = "password"
Connect-VIServer -Server $vcServer -Username $vcUsername -Password $vcPassword

# Set the duration of esxtop capture in seconds
$durationInSeconds = 300

# Get all the hosts in the vCenter Server
$hosts = Get-VMHost

# Iterate through each host
foreach ($host in $hosts) {
Write-Host "Capturing esxtop on host: $($host.Name)"

# Generate the esxtop CSV file path
$csvPath = "C:\esxtop_$($host.Name)_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"

# Run esxtop command and save the output to the CSV file
$esxtopCommand = "esxtop -b -a -d 1 -n $($durationInSeconds + 1) > $csvPath"
Invoke-VMScript -VMHost $host -ScriptText $esxtopCommand -ScriptType Bash

# Wait for the duration of the esxtop capture
Start-Sleep -Seconds $durationInSeconds
Write-Host "Esxtop captured on host: $($host.Name)"
}

# Disconnect from the vCenter Server
Disconnect-VIServer -Server $vcServer -Confirm:$false

Before running the script, make sure to replace “vcenter-server.example.com”, “username”, and “password” with the appropriate values for your vCenter Server. Also, adjust the $csvPath variable to specify the desired location and file naming convention for the esxtop CSV files.

This script connects to the vCenter Server, retrieves all the hosts, runs the esxtop command on each host with the desired parameters, and saves the output to a separate CSV file for each host. It then waits for the specified duration to complete the esxtop capture. Finally, it disconnects from the vCenter Server.

Please note that capturing esxtop data can generate large amounts of data, so ensure you have sufficient storage capacity and consider adjusting the parameters and duration according to your requirements.

Ashutosh Dixit

I am currently working as a Senior Technical Support Engineer with VMware Premier Services for Telco. Before this, I worked as a Technical Lead with Microsoft Enterprise Platform Support for Production and Premier Support. I am an expert in High-Availability, Deployments, and VMware Core technology along with Tanzu and Horizon.

Leave a Reply