Administering VMware Using PowerShell#2: Essential PowerCLI Cmdlets for Efficient VMware Management

VMware PowerCLI is a powerful tool, that provides an automation interface for managing and configuring VMware products through a collection of PowerShell modules. It is specifically designed to help IT professionals automate administrative tasks, push changes to hosts or VMs, and collect relevant data​.

PowerCLI’s functionality depends on the type of licenses installed in your vSphere environment. For example, hosts with a free hypervisor version can only be queried by PowerCLI in “read-only” mode​.

Prerequisites for VMware PowerCLI

Before you start with PowerCLI, ensure you have the compatible PowerShell versions and the .Net Framework installed on your system​.

How to Install VMware PowerCLI

The installation procedure varies depending on whether your machine has internet access or not. For a machine with internet access, open a PowerShell prompt and install the modules using: Install-Module VMware.PowerCLI -Scope CurrentUser. For a machine without internet access, download PowerCLI as a zip file from the VMware website and transfer the content into the modules folder of the offline system​.

You may also need to change your PowerShell execution policy to allow scripts to be run. You can check your current policy with Get-ExecutionPolicy and change it to “RemoteSigned” with Set-ExecutionPolicy​.

Connecting to a VirtualCenter Server or Host Server

To connect to a VirtualCenter Server or Host Server, use the Connect-VIServer cmdlet and provide a value to the Server parameter:

Connect-VIServer -Server <server>​.

Essential PowerCLI Cmdlets for Efficient VMware Management

While there are many cmdlets available in PowerCLI, some of the most commonly used include Get-VM, Set-VM, New-VM, Start-VM, and Stop-VM.

  1. Get-VMHost: This cmdlet retrieves information about ESX hosts in your VMware environment. For example, you can use it to obtain information about a specific host by providing the name of the host as a parameter​.
  2. New-VM: The New-VM cmdlet creates a new virtual machine in your vSphere environment. You can specify parameters such as the name, the host, the location, the datastore, and the disk size when creating the new VM​.
  3. Set-VM: This cmdlet modifies the properties of an existing virtual machine. You can use it to change settings such as the number of CPUs, the amount of memory, the network adapter, and the hard disk size​.
  4. Remove-VM: This cmdlet removes a specified virtual machine from your vSphere environment. You should be careful when using this cmdlet as it permanently deletes the VM​.
  5. Get-VM: This cmdlet retrieves information about the virtual machines in your vSphere environment. It’s particularly useful for generating reports or getting an overview of your VMs​.

Here are some small script examples of using Set-VM:

Convert a VM to a template:

$template = Get-VM VM | Set-VM -ToTemplate -Name VMTemplate

Upgrade memory and CPU count of VMs:

Get-VM -Location ResourcePool01 | Set-VM -MemoryGB 2 -NumCPU 2

Upgrade the virtual hardware version of a VM:

Set-VM -VM VM -Version v7

Revert a VM to a certain snapshot:

$snapshot = Get-Snapshot -VM $vm -Name "Initial state"; Set-VM -VM $vm -Snapshot $snapshot

Apply a customization specification on a VM:

$spec = Get-OSCustomizationSpec -Name FinanceDepartmentSpec; Set-VM -VM $vm -OSCustomizationSpec $spec

Change the name, description, and guest ID of a VM:

Set-VM $vm -Name "Web Server" -GuestID winNetStandardGuest -Description "Company's web server"​.

These examples demonstrate how you can automate and streamline your VMware administration tasks using PowerCLI.


Please note that the list of essential cmdlets for efficient VMware management is not exhaustive. VMware PowerCLI has a wide range of cmdlets that can be used to automate various tasks in a VMware environment. The cmdlets you use will depend on your specific needs and the tasks you need to perform.

Furthermore, the installation and usage of PowerCLI require some understanding of PowerShell. If you’re

not familiar with PowerShell, it might be helpful to spend some time learning the basics of PowerShell scripting and command-line interfaces before diving into PowerCLI.

Moreover, remember to always perform actions with care, especially when it comes to automating tasks. While automation can significantly improve efficiency, it also has the potential to propagate errors at a much faster rate than manual administration. Always test your scripts in a controlled environment before deploying them in a production environment.

Finally, keep in mind that this article focuses on the basic aspects of using PowerCLI for VMware management. There are more advanced topics, like the integration of PowerCLI with other systems and advanced automation techniques, which are beyond the scope of this article.

By mastering PowerCLI, you can significantly improve your efficiency as a VMware administrator, reduce the risk of errors, and free up more time to focus on strategic tasks.

Leave a comment