Learning Objectives
# Print the first few rows
print(df.head())
- Automate export of VMware inventory and reports to CSV/Excel using PowerCLI.
- Use Python to parse, filter, and visualize VMware report data.
- Build a basic VM inventory dashboard in Python.
- Understand workflow visualization with an diagram.
My Personal Repository on GitHub
# Plot PowerState distribution
plt.figure(figsize=(6,4))
state_counts.plot(kind=’bar’)
plt.title(‘VM Power State Distribution’)
plt.xlabel(‘Power State’)
plt.ylabel(‘Number of VMs’)
plt.tight_layout()
plt.show()
Prerequisites
- Completed Articles 1–4.
- PowerCLI, Python, and the Python modules
pandas
andmatplotlib
are installed:pip install pandas matplotlib
- VMware vCenter or ESXi access.
1. Exporting VM Inventory with PowerCLI
# Install the module (run once)
Install-Module -Name ImportExcel -Scope CurrentUserBy the end of this article, you will:
You can also use PowerCLI to export reports in Excel format with Export-Excel
from the ImportExcel PowerShell module.VMware Repository on GitHubLet’s create a PowerShell script that exports VM info (Name, PowerState, Guest OS, IP, CPU, Memory) to CSV.
2. Reading and Visualizing the CSV with Python
# Export VM data
Get-VM | Select-Object Name, PowerState, @{N=”GuestOS”;E={$_.Guest.OSFullName}}, @{N=”IPAddress”;E={$_.Guest.IPAddress -join ‘, ‘}}, NumCpu, MemoryGB |
Export-Csv -Path C:Tempvm_inventory.csv -NoTypeInformation
Disconnect-VIServer -Server * -Confirm:$false Save as # Import PowerCLI
Import-Module VMware.PowerCLIYou have learned to export VMware inventory to CSV/Excel and create basic data visualizations with Python.
This capability is a foundation for dashboards, audit reports, and capacity analysis for your virtual infrastructure.import pandas as pd
import matplotlib.pyplot as plt# Count VMs by PowerState
state_counts = df['PowerState'].value_counts()Now, your Python scripts can also read .xlsx
files using pandas.read_excel()
.
3. Diagram: Reporting and Visualization Flow
4. Advanced: Exporting Directly to Excel
export_vm_inventory.ps1
:
Next up: In Article 6, you will add error handling and logging to your scripts, with practical examples including integration with Aria for Logs.
5. Troubleshooting Tips
- If you see file permission errors, confirm you have write access to the target folder.
- For Python plotting errors, ensure you installed
matplotlib
andpandas
. - Large vCenters may export thousands of rows; filter in PowerCLI or Python for smaller data sets.
6. Further Reading
7. Conclusion and Next Steps
# Group by GuestOS
os_counts = df[‘GuestOS’].value_counts().head(10)
plt.figure(figsize=(8,4))
os_counts.plot(kind=’barh’)
plt.title(‘Top 10 Guest OS Types’)
plt.xlabel(‘Number of VMs’)
plt.tight_layout()
plt.show()
The following Python script reads your exported CSV and visualizes basic VM stats.