Skip to content
Indus LeveL
vmware powercli esxi automation powershell sysadmin virtualization

Automating VMware ESXi Management and Licensing with PowerCLI

A comprehensive sysadmin guide to automating VMware ESXi host administration, bulk licensing, VM inventory reporting, and SSH service toggling using PowerCLI and vim-cmd.

2 min read
Cover illustration representing VMware vSphere ESXi virtualization, PowerShell automation, and PowerCLI scripting

Managing large clusters of standalone VMware ESXi hypervisors across multiple data centers can become incredibly tedious if you rely solely on the vSphere Web Client or manual ESXi shell logins. When administering dozens of hosts during mass infrastructure updates or license renewals, automation is essential.

VMware PowerCLI is a powerful PowerShell module that provides over 800 cmdlets for managing vSphere environments. When paired with native ESXi shell utilities like vim-cmd, you can instantly query VM inventories, assign license keys in bulk, and toggle host services across hundreds of hypervisors simultaneously.

In this guide, I will walk you through installing PowerCLI, connecting to ESXi clusters across different data centers, executing bulk license assignments, generating VM summary reports, and managing ESXi SSH services programmatically.

Prerequisites

You will need a Windows administrative control node with PowerShell running as Administrator, and network reachability to your ESXi management interfaces.


Step 1: Installing and Configuring PowerCLI

Open PowerShell as Administrator and install the official VMware PowerCLI module directly from the PowerShell Gallery.

# Install PowerCLI module from PowerShell Gallery
Install-Module -Name VMware.PowerCLI -Force -AllowClobber

# Set execution policy to allow script execution
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

Step 2: Connecting to ESXi Hypervisors across Data Centers

To administer ESXi hosts, establish authenticated sessions using Connect-VIServer. Below is a structural blueprint for connecting to hypervisors distributed across multiple enterprise data centers.

# Connect to Staging Cluster Hypervisors
Connect-VIServer -Server 10.110.207.170 -User root -Password Randompassword
Connect-VIServer -Server 10.110.207.90  -User root -Password Randompassword
Connect-VIServer -Server 10.110.207.92  -User root -Password Randompassword

# Connect to Production Cluster Hypervisors
Connect-VIServer -Server 10.112.207.120 -User root -Password Randompassword
Connect-VIServer -Server 10.112.207.146 -User root -Password Randompassword
Connect-VIServer -Server 10.112.207.155 -User root -Password Randompassword
Connect-VIServer -Server 10.112.207.81  -User root -Password Randompassword

Automated PuTTY SSH Tunneling Cheatsheet

If you need to drop into the ESXi shell for low-level maintenance across specific data center zones (West-DC1, East-DC1, Central-DC1, North-DC1), you can automate PuTTY CLI execution:

# West-DC1 Cluster Hosts
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@10.110.3.65 -pw Randompassword

# East-DC1 Cluster Hosts
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@10.112.3.80 -pw Randompassword
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@10.112.3.77 -pw Randompassword

# Central-DC1 Cluster Hosts
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@10.114.7.205 -pw Randompassword
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@10.114.7.206 -pw Randompassword

# North-DC1 Cluster Hosts
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@192.168.180.32 -pw Randompassword
c:\"Program Files (x86)\PuTTY"\putty.exe -ssh root@192.168.180.33 -pw Randompassword

Step 3: Bulk ESXi Licensing via PowerCLI and vim-cmd

Assigning or renewing ESXi licenses manually across dozens of standalone hosts is highly inefficient. You can apply license keys instantly using PowerCLI or native ESXi shell one-liners.

Method 1: PowerCLI Native License Assignment

# Assign license key to connected ESXi host
Set-License -key "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"

# Verify license assignment across all connected hosts
Get-VMHost | Select-Object -Property Name,LicenseKey

Method 2: Native ESXi Shell Licensing (vim-cmd)

When logged into the ESXi CLI directly, apply and verify license keys using vim-cmd:

# Apply license key
vim-cmd vimsvc/license --set XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

# Verify license details
vim-cmd vimsvc/license --show | egrep "name|serial:"

Method 3: Advanced vSphere API License Manager View

For automated script integrations, access the low-level LicenseManager API view directly:

$LicenseManagerView = Get-View -Id "LicenseManager-ha-license-manager"
$LicenseManagerView.UpdateLicense("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", $null)

Step 4: Managing ESXi SSH Services Programmatically

Keeping SSH enabled permanently on ESXi hosts violates security best practices and triggers warning alarms in vCenter. Using PowerCLI, you can dynamically query, start, and stop the SSH daemon (TSM-SSH) across your entire cluster.

# 1. Query SSH service status across all hosts
Get-VMHost | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" } | Select-Object VMHost, Label, Running

# 2. Enable and start SSH service across all hosts
Get-VMHost | ForEach-Object { Start-VMHostService -HostService ($_ | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" }) }

# 3. Stop SSH service across all hosts
Get-VMHost | ForEach-Object { Stop-VMHostService -HostService ($_ | Get-VMHostService | Where-Object { $_.Key -eq "TSM-SSH" }) }

Step 5: Generating Bulk VM Inventory Reports

To perform auditing or capacity planning, you can extract a complete inventory of all virtual machines, including their assigned vCPUs, memory, and IP addressing, using vim-cmd.

Execute this one-liner on your ESXi hypervisor to generate a clean summary report of all active virtual machines:

for i in `vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`; do
    vim-cmd vmsvc/get.summary $i | egrep "numCpu|name|ipAddress"
    echo "---------"
done

References

Back to Blog
Share:

Follow along

Stay in the loop — new articles, thoughts, and updates.