VMware PowerCLI Super Detailed Tutorial – Complete Guide with Commands & Examples
What is VMware PowerCLI?
VMware PowerCLI is a command-line and scripting toolset provided by VMware, based on Windows PowerShell, specifically designed for managing and automating VMware virtualization environments (such as vSphere, vCloud, vSAN, etc.). It achieves comprehensive control over ESXi hosts and vCenter Server by calling the vSphere Web Services API, making it a core tool for IT administrators to improve operational efficiency.
VMware PowerCLI is a powerful command-line tool built on Microsoft PowerShell that allows administrators to automate VMware vSphere environments. With PowerCLI, you can manage ESXi hosts, vCenter, virtual machines, storage, and networking through scripts instead of manual tasks.
Core Functions and Application Scenarios of VMware PowerCLI:
1. Infrastructure Automated Deployment
• Batch creation of data centers, clusters, and resource pools:
New-Datacenter -Name "NYC_DataCenter" #Create data center
New-Cluster -Name "Cluster" -HAEnabled -DRSEnabled #Cluster with HA and DRS enabled
• Automatically add ESXi hosts to clusters, supporting rapid SSL certificate integration (**Force** parameter)
2. Virtual Machine Full Lifecycle Management
• Virtual machine creation/cloning/deletion, hardware configuration (CPU/memory/disk expansion)
• Snapshot management (creation, restoration, deletion) and VMware Tools updates
3. Resource Optimization and Monitoring
• Fine-grained allocation of CPU, memory resource pools (e.g., **New-ResourcePool**)
• Collect performance data and generate HTML reports to achieve capacity planning and fault early warning
4. High Availability and Disaster Recovery
• Configure cluster high availability (HA) policies (e.g., fault tolerance level **HAFailoverLevel 2**)
• Integration with Site Recovery Manager (SRM), scripted custom disaster recovery plans
5. Network and Storage Management
• Distributed Switch (vDS) configuration, port group policy management (**VMware.VimAutomation.Vds** module)
• Storage policy automation, datastore monitoring (**VMware.VimAutomation.Storage** module)
Offline Installation of PowerCLI
Offline installation of PowerCLI requires administrators to manually download the installation package and install it using the provided commands. This is suitable for environments without network access or with poor network conditions.
1. Before installing PowerCLI, check the Broadcom product interoperability matrix to see which version of PowerCLI is compatible with your actual VMware products.
https://interopmatrix.broadcom.com/Interoperability
2. After determining the PowerCLI version to install, go to the Broadcom official website to download PowerCLI (requires logging in with a Broadcom account to download). For this experimental environment, the latest version PowerCLI 13.3 is selected.
https://developer.broadcom.com/tools/vmware-powercli/latest
If you want to download other versions, you can select them as needed in the upper-right corner of the page.
3. After the download is complete, unzip the ZIP package.
4. Open PowerShell as an administrator and use the following command to check the PowerShell module path:$env: PSModulePath
$env: PSModulePath
5. This command will output all PowerShell module paths (each path separated by a;sign). Select one of them and open the path in File Explorer.
6. Copy and paste all files unzipped from the ZIP file into one of PowerShell's module paths.
7. First, use the cd command to switch to the path where the PowerCLI module is located, i.e., where the unzipped files were pasted, such as C:\Program\WindowsPowerShell\Modules. Then use Get-ChildItem * -Recurse | Unblock-File to unblock these files to prevent PowerShell from distrusting these PowerCLI modules.
cd C:\Program\WindowsPowerShell\Modules
Get-ChildItem * -Recurse | Unblock-File
8. You can use the Get-Module -Name VMware.PowerCLI* -ListAvailable command to verify if the PowerCLI module is available.
Get-Module -Name VMware.PowerCLI* -ListAvailable
Online installation of PowerCLI
To install VMware PowerCLI online, only one command is needed, but it heavily relies on the network environment.
1. Open PowerShell as an administrator, then run the PowerCLI online installation command.
Install-Module VMware.PowerCLI
2. During the installation, some authorization operations will be prompted. Allow all of them and wait for the installation to complete.
At this point, VMware PowerCLI is installed! If you have any questions, feel free to ask in the comments below.
Advanced PowerCLI Use Cases
-
Automating VM provisioning
-
Generating inventory reports (CPU, memory, storage usage)
-
Managing datastores and snapshots
-
Performing bulk configuration changes
-
Automating disaster recovery tasks
Best Practices for PowerCLI
-
Use descriptive script names for easy maintenance.
-
Run scripts in a test environment before production.
-
Store credentials securely instead of plain text.
-
Keep PowerCLI updated to match vSphere versions.