Administering VMware Using PowerShell#1: An Introduction to PowerCLI

Virtualization has revolutionized the IT world, making it possible to run multiple operating systems and applications on a single physical server. A leader in this space is VMware, known for its robust and efficient solutions. While VMware offers a GUI-based management console, mastering VMware administration with PowerShell can take your skills to the next level. PowerShell, a command-line interface from Microsoft, is a powerful tool for automating tasks and managing Windows-based systems. VMware has embraced PowerShell with VMware PowerCLI, a collection of PowerShell modules that provide cmdlets to manage a wide range of VMware products.

Understanding VMware PowerCLI

VMware PowerCLI is a versatile tool that allows IT professionals to perform most vSphere administrative tasks and automate them. For instance, suppose you have a chunky vSphere cluster made up of 50 nodes, and you need to make a change to detach one or more LUNs on all of them. You could spend hours making the change on each host manually in the vSphere Client, or you can use PowerCLI to execute the change on all the nodes in minutes, assuming such changes are performed carefully and knowledgeably.

But pushing changes to hosts or VMs isn’t the only benefit VMware PowerCLI brings to the table. You can also use it to collect data relevant to a specific use case in a single place. There are ready-to-use scripts available, such as Alan Renouf’s vCheck, that act as a framework to email HTML reports based on what you want to monitor. This script is backed by VMware themselves. PowerCLI also provides integration with applications like vRealize Operations, NSX, VSAN, Horizon, and VMware Cloud platforms, making it an indispensable tool in a VMware environment​.

However, it’s important to understand that there are some limitations to VMware PowerCLI based on which type of licenses are installed in your vSphere environment. Hosts licensed with the free hypervisor version can only be queried by PowerCLI in “read-only” mode, meaning you can only use commands that collect information. Commands used to make changes like Set-, Add-, New-, or Remove- will not work. Any paid license of vSphere will be enough to provide full access to all of PowerCLI’s functions and features​.

Getting Started with VMware PowerCLI

VMware PowerCLI 12.2.0 is compatible with Windows PowerShell 5.1 and PowerShell 7. To verify the version of PowerShell installed on your system, open up a PowerShell prompt and display the content of $PSVersionTable.PSVersion. If the version installed on your system is outdated, you will need to install the Windows Management Framework 5.1 or PowerShell 7 depending on your preference and system compatibility​.

In addition to running a recent version of PowerShell, you also need to ensure that .Net Framework is installed in a supported version. You can quickly check which version of .Net Framework is installed via the Registry Editor or using a PowerShell one-liner that checks the same registry key. If the version you are currently running is outdated, download and install the latest version on Microsoft’s repository​.

Once the prerequisites are met, you can proceed to install VMware PowerCLI. For machines with internet access, open a PowerShell prompt and install the modules using Install-Module VMware.PowerCLI -Scope CurrentUser. The modules will be automatically downloaded and stored in the correct folder. To update PowerCLI, uninstall the existing version using Get-module VMware.* -listAvailable | Uninstall-Module -Force and then follow the install procedure outlined previously​. For machines without internet access, you can download PowerCLI as a zip file from

the VMware website, transfer the file to your offline machine, and copy all the folders present in the zip to your PowerShell Modules folder. To update PowerCLI on an offline machine, delete the existing PowerCLI module folders and follow the procedure outlined previously​.

Before you start using VMware PowerCLI, check your PowerShell execution policy. Execution policies are a security mechanism that determines if files can be loaded in PowerShell such as config files, modules, scripts, etc. You can find your current execution policy by running Get-ExecutionPolicy. You may need to change the default execution policy to be able to run the scripts you wrote. Unless a GPO changed the default setting, you won’t need to if you are on a Windows Server OS. However, it is required for Windows client OS (i.e., Windows 10) as the default is set to Restricted, you will need to change it to RemoteSigned with the command Set-ExecutionPolicy​.

Connecting to a VMware Server with PowerCLI

Once PowerCLI is installed and configured, the next step is to connect to your VMware server. The Connect-VIServer cmdlet is used to establish a connection with a VirtualCenter Server or Host Server. You provide the server address as a parameter to the cmdlet, like so: connect-viserver -server <server>​.

Beyond connecting to the server, VMware PowerCLI offers a wealth of commands for managing your VMware environment. You can manage virtual machines, data stores, networks, and more. While the scope of what can be done with PowerCLI is beyond this introduction, resources like the VMware PowerCLI User’s Guide and various online communities offer detailed information and examples to help you learn and master this powerful tool.

By using VMware PowerCLI for managing your VMware environment, you gain the benefits of automation, speed, and flexibility. Once you get the hang of it, you might find that many tasks are quicker and easier with PowerCLI than with the GUI. The key to becoming proficient with PowerCLI is practice and experimentation. Start with simple tasks, and gradually tackle more complex operations as your comfort level and understanding grow.

Leave a comment