Since some time, VMware provides PowerCLI which is a set of modules for VMware vSphere. Except if you were in a cave last 10 years, you should know that PowerShell is a powerful scripting language. Initially, PowerShell enabled to manage only Windows Workstation or Server, but since sometimes, a lot of vendors make their own modules to manage their solutions (such as Veeam, VMware and so on). Moreover, PowerShell is available on Linux.

For my job, I always use PowerShell. I’m a lazy guy, and if I have to make something two times, I make a script. This is the same thing for VMware vSphere. In this topic, we’ll see how to connect to vCenter and some commands to start.

Install or update PowerCLI

After a while, VMware has published the PowerCLI in the PowerShell gallery. In this way, you don’t have to install an application anymore to use PowerCli.

N.B: To follow this part, you need PowerShell v5 at least. If you are not using Windows 10 or Windows Server 2016, you can install the latest Windows Management Framework.

To install PowerCli from the PowerShell gallery you need Internet Access. Then run:

install PowerCli from the PowerShell gallery

If you have already installed PowerCLI from the PowerShell gallery, you can run the following command:

N.B: If you have installed the PowerCLI from executable, you need to remove it and install PowerCLI with the above command.

Update Module Name with PowerCLI

When PowerCLI is installed, you can run the below command. You can see that 620 cmdlet exists for VMware vSphere. That’s a lot!

PowerCLI command

Connect to VMware vCenter

To manage VMware vSphere you have to connect to VMware vCenter. First, run a Get-Credential to store in variable credentials to connect to vCenter. Then run the following command:

Connect to VMware vCenter via PowerCLI

Get information from vCenter

Now that you are connected to the vCenter, you can gather information. First, I get information about a Virtual Machine with the command Get-VM.

Get information from vCenter via PowerCLI

You can also get information about VM Host (ESXi) connected to the vCenter. You can get a lot of useful information by running, for example, Get-VMHost | FL *.

get the information about VM Host connected to the vCenter

Because my cluster is running with vSAN, I can also get information about vSAN configuration. Cmdlet provided by PowerCLI enables to manage VMware vSphere included VMware NSX, VMware vSAN, and so on.

get information about vSAN configuration via PowerCLI

StarWind VSAN for vSphere uses your local hypervisor cluster to create fault-tolerant and robust virtual shared storage, eliminating the need to buy a costly physical SAN. You can deploy it on any off-the-shelf hardware you already got. Thanks to mirroring of internal hard disks and flash between hypervisor servers, you get a 2-node Highly Available cluster. There is no need for a witness instance, and you’re not restricted on storage size, features, or number of VMs. Your IT-environment will not only achieve constant uptime and skyrocketing performance, you will also save a good deal on CapEx and OpEx.
Find out more about ➡ StarWind VSAN for vSphere

Create a VM from a template

Getting information is really nice, but you can also create a VM. For example, you have created one or several templates and now you want to create a hundred VMs from these templates. The fastest way is to use PowerCLI. Below, you can see that I get a VM template from VMware vCenter.

Create VM from a template via PowerCLI

Then I get the VM Host inside the Cluster-ESX01 cluster, sort them by memory usage, and then select the host with less memory usage. Next, I create a VM in this VM Host with the template w2016-Core-v1.0.

create a VM in the VM Host with the template

Next, I’m connecting to the vCenter and as you can see, the VM is creating.

vSphere Client VM summary

Update a cluster from a baseline

Another example of PowerCLI regards the updating of your VMHosts. By running Get-Baseline and get-Compliance, you can get information about the baseline and the compliance status of your VMHosts.

Update a cluster from a baseline via PowerCLI

Then you can get your baseline and add it in a variable. Then run:

get the baseline and add it in a variable via PowerCLI

In the below screenshot, you can see that the cluster is updating.

vSphere Client cluster infomation


PowerShell is a powerful scripting language. It’s great that VMware has made modules to manage VMware vSphere, including VMware NSX and vSAN. Thanks to these modules, you can automate a lot of tasks such as the VM creation, the host deployment, and so on.

Views All Time
Views Today
Appreciate how useful this article was to you?
1 vote, average: 1.00 out of 51 vote, average: 1.00 out of 51 vote, average: 1.00 out of 51 vote, average: 1.00 out of 51 vote, average: 1.00 out of 5
1 out of 5, based on 1 review
Back to blog
The following two tabs change content below.
Romain Serre
Romain Serre
Senior consultant at Exakis
Romain Serre works in Lyon as a Senior Consultant. He is focused on Microsoft Technology, especially on Hyper-V, System Center, Storage, networking and Cloud OS technology as Microsoft Azure or Azure Stack. He is a MVP and he is certified Microsoft Certified Solution Expert (MCSE Server Infrastructure & Private Cloud), on Hyper-V and on Microsoft Azure (Implementing a Microsoft Azure Solution).