Learning Objectives
By the end of this article, you will:
- 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
Prerequisites
- Completed Articles 1–4.
- PowerCLI, Python, and the Python modules
pandasandmatplotlibare installed:pip install pandas matplotlib - VMware vCenter or ESXi access.
1. Exporting VM Inventory with PowerCLI
Let’s create a PowerShell script that exports VM info (Name, PowerState, Guest OS, IP, CPU, Memory) to CSV.
Save as export_vm_inventory.ps1:
# Import PowerCLI
Import-Module VMware.PowerCLI
# Connect to vCenter (update details)
Connect-VIServer -Server <vcenter-address> -User <username> -Password <password>
# 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:\Temp\vm_inventory.csv -NoTypeInformation
Disconnect-VIServer -Server * -Confirm:$false
2. Reading and Visualizing the CSV with Python
The following Python script reads your exported CSV and visualizes basic VM stats.
import pandas as pd
import matplotlib.pyplot as plt
# Load the CSV file
df = pd.read_csv(r"C:\Temp\vm_inventory.csv")
# Print the first few rows
print(df.head())
# Count VMs by PowerState
state_counts = df['PowerState'].value_counts()
# 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()
# 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()
3. Diagram: Reporting and Visualization Flow
4. Advanced: Exporting Directly to Excel
You can also use PowerCLI to export reports in Excel format with Export-Excel from the ImportExcel PowerShell module.
# Install the module (run once)
Install-Module -Name ImportExcel -Scope CurrentUser
# Export to Excel
Get-VM | Select-Object Name, PowerState, NumCpu, MemoryGB |
Export-Excel -Path C:\Temp\vm_inventory.xlsx -AutoSize
Now, your Python scripts can also read .xlsx files using pandas.read_excel().
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
matplotlibandpandas. - Large vCenters may export thousands of rows; filter in PowerCLI or Python for smaller data sets.
6. Further Reading
- VMware PowerCLI Documentation
- pandas Documentation
- matplotlib Documentation
- ImportExcel PowerShell Module
7. Conclusion and Next Steps
You 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.
Next up: In Article 6, you will add error handling and logging to your scripts, with practical examples including integration with Aria for Logs.
Learning Objectives By the end of this article, you will: My Personal Repository on GitHub VMware Repository on GitHub Prerequisites 1. Introduction...
