A Guide to Fumbling Through VMware PowerCLI

VMware’s PowerCLI can come in quite handy in a vSphere environment, especially when you are managing a large number of hosts.  Sure, you can find sample scripts on the Internet to run, but it is also a good idea to at least get a fundamental understanding of how PowerCLI works.  After all, you would not want to let a script loose in your environment if you did not have any idea what it did.

The good thing about PowerCLI is there are a number of features built right in to help you get going.  I like to learn by doing, so here are some ideas on how to fumble through PowerCLI to get started.  This is your self learning guide to VMware PowerCLI, from finding your PowerCLI download to connecting to vCenter with PowerCLI and beyond!

First things first…

How to Download VMware PowerCLI

First things first, you will need to download VMware PowerCLI and install PowerCLI to start using it.  PowerCLI requires PowerShell to already be installed one the system you plan on using.  The best place to download VMware PowerCLI from is the VMware Code site.  You can easily download the latest versions, as well as previous versions of VMware PowerCLI.

VMware PowerCLI Download VMware Code

As you can see, VMware PowerCLI made a huge jump in versions from VMware PowerCLI 6.5.4 to VMware PowerCLI 10.0.0.  While I do not work for VMware, so I do not know their logic for this jump in versioning, my best guess is because the features and functionality of PowerCLI 10.0.0 have increased so dramatically.

VMware PowerCLI 10 now supports Mac OS X and Linux operating systems.  Wow!  With a couple prerequisites, you can be administering your VMware vSphere environment from any operating system you would like!  You must first install PowerShell Core on your system, and then you will be able to install VMware PowerCLI on Mac or install VMware PowerCLI on Linux.  For instructions on how to do this, be sure to take a look at the VMware PowerCLI Blog.

Getting Started With VMware PowerCLI Basics

Now that you have installed VMware PowerCLI on your system of choice, you are ready to get started!

The Most Basic PowerCLI Command: Connect to vCenter

First and foremost, you will want to connect to a server.  We are going to now cover the most basic and most important PowerCLI command.

I am going to connect to my vCenter server by using the following command:

Connect-VIServer vc.lab.local

powecli connect viserver vcenter vmware vsphere

Connect-VIServer is a command you are going to use over and over, so make sure to commit it to memory!  After we have connected to vCenter with PowerCLI  we will start with the basics by listing our hosts and virtual machines.


powecli get vm get vm host vmware vsphere

Something to remember is that you do not connect to your host, you connect to your virtual machine host.  Otherwise, simply typing Get-Host won’t get you anywhere, because it is just going to tell you about the system you are running PowerCLI on.

So what else can we do?  Type Get-VICommand to see the commands you can choose from.  You are going to end up with a very long list of things you can do with PowerCLI.

Learning PowerCLI Basics with vSphere Networking

One of the most common tasks a vSphere administrator will face is to configure networking on an ESXi host.  PowerCLI can make this task quite a bit easier, so we are going to focus on vSphere Networking PowerCLI commands to teach ourselves, since there are so many different things you can do with powerCLI.

To try to narrow things down, let’s look for some commands we can run on virtual switches by typing Get-VICommand *switch.

powercli get vicommand switch vmware vsphere

How do we find out more about our switches?  That depends on the type.  You will see VDSwitch for Distributed vSwitches, and VirtualSwitch for Standard vSwitches.  Finding out more about our Standard vSwitches is easy.  We can use  Get-VirtualSwitch to find out what switches we have in our environment.  

Notice we also get information on Distributed vSwitches, but PowerCLI is nice enough to warn us that information may not be around forever and we should use Get-VDswitch.

power cli get virtualswitch distributed switch vmware vsphere

PowerCLI is not case sensitive, as illustrated above, so you can type your commands in lower case, upper case, or any combination you feel like.  PowerCLI also features tab complete, once you’ve started typing a command.  Hit tab to cycle through commands with the prefix you’ve typed until you find the one you’d like.

We can be a lot more specific than just listing the switches in our environment.  To find out how to use the Get-VirtualSwitch command, type

Get-Help Get-VirtualSwitch

powercli get help vmware vsphere

You will be able to find out what the command does, as well as the syntax.  PowerCLI will also tell you how to get more information on the command, such as examples and the full details by using Get-Help Get-VirtualSwitch -examples and Get-Help Get-VirtualSwitch -detailed.

Just running Get-VirtualSwitch gives us some information, but not many details.  To get more details about our switches, type

Get-VirtualSwitch | Get-Member

powercli get virtualswitch get member information vmware vsphere

This will tells which properties we can work with or find out more about from our Virtual Switch.  When we use |, this means we are passing the output of one command to another.

Now, try Get-VirtualSwtich | Format-Table

powercli get virtualswitch table output vmware vsphere

Now we have some information on our switches formatted in an easy to read table.  We’ve got duplicates of vSwitch0 and vSwitch1, so it is hard to say where those switches reside.  Let’s take a look at our output from Get-VirtualSwitch | Get-Member, and add some attributes to our table.

Get-VirtualSwitch | Format-Table Name,Datacenter,Mtu,VMhost
Screen Shot 2016-05-17 at 11.39.57 AM

Now we can see which host each vSwitch1 and vSwitch0 are on.  Since the other switches are distributed switches, they don’t have a host listed in the table.

So you’ve been playing around with PowerCLI and getting a feel for things.  What comes next?  Getting started with PowerCLI is always easiest when you think in the context of daily administrative tasks.  Besides giving you some common use cases, you’ll learn new ways to take a look around your vSphere environment with PowerCLI and be able to relate it to what you are used to doing within the vSphere client.

After getting used to finding information, you’ll find yourself beginning to write scripts and one-liners to be able to get and set specific information.  This can be the fist step in saving time and effort in big ways with scripting and automation on PowerCLI.

This article is part of the Fumbling Through PowerCLI Series.
Part 1 – A Guide to Fumbling Through PowerCLI
Part 2 – Continuing to Get Set With PowerCLI and Standard vSwitches

Part 3 – Get Set With PowerCLI and Distributed Virtual Switches, Part 1

Stay tuned for more fumbling through PowerCLI, focused on configuring vSphere networking components.  Remember, when in doubt, you can always Get-Help!

1 thought on “A Guide to Fumbling Through VMware PowerCLI”

Leave a Comment