Getting Started with VMware PowerCLI
With vSphere 5, the traditional ESX Server has gone away and the permanent replacement is ESXi Server. Of course, the big difference is that ESXi Server doesn’t have a service console. That service console was a special privileged virtual machine that was used for administration and scripting functions for an ESX host. ESXi Servers, with their tiny Busy-box Linux super-slim console isn’t going to work for scripting and isn’t efficient for mass administration & configuration of ESXi Servers.
VMware recommend one of two options with one being the vSphere Management Assistant (vMA). For information on vMA, see my video “Using the vSphere Management Assistant”. However, scripting in vMA will be done, very likely, using Perl. For most VMware Admins, Microsoft’s PowerShell is a more appealing option as it works for a wide range of Microsoft and third-party products. Thus, your knowledge of PowerShell would allow you to script Windows Server tasks, Exchange Server tasks, and more. Well, that “more” is also VMware vSphere server tasks. When you use PowerShell with VMware’s “cmdlets”, it’s called PowerCLI and that is the best option for mass vSphere administration and scripting.
What You Need to Use VMware PowerCLI
Minimally, to use VMware PowerCLI, all you have to do is to download and install the VMware PowerCLI application (free). You can download this from the VMware PowerCLI Community site.
Make sure that you download version 5.0 or later (5.0.1) because, at the time of writing this article, version 5.0.1 is the latest and is compatible with vSphere 5.
This community site offers a lot more than just the PowerCLI software. They also house:
- The official VMware PowerCLI documentation
- A free PowerCLI Workshop presentation and scripts
- A link to the PowerCLI Blog (lots of good script examples there)
- PowerCLI sample code
- A discussion forum where you can post your PowerCLI questions
Downloading and Installing VMware vSphere PowerCLI
As I said, PowerCLI is actually just a simple Windows installation. Downloading it will require a free VMware account but will only take a few minutes. The 91MB download may take longer to download than it takes to actually install.
Once downloaded, here’s what the installation looks like:
During the installation, you may see a message that looks like this. If you do, you can click continue but you will have to resolve this later.
Once installed, you’ll have a group of programs under your VMware program group that looks like this:
To actually run PowerCLI, you would run the program described as VMware vSphere PowerCLI and here’s what you would see:
Initially, a black window with a command prompt is very intimidating for new PowerCLI admins so please don’t get scared off at this point. You don’t have to spend your whole PowerCLI life at this command prompt. There are easier ways to use PowerCLI (and I’ll show them to you later).
First, let’s fix that nasty-looking red error (the same error that popped up during installation).
Fixing PowerCLI Execution Policy Errors by Setting RemoteSigned
I’m not going to claim to be an expert on PowerCLI security nor am I even going to go into the different PowerCLI execution policy settings that are possible. Instead, I’m just going to show you how to resolve this error the quickest way possible so that you can run some PowerCLI scripts.
This annoying error seems to come up every time I go to run a PowerCLI script and I always have to Google what I need to do to resolve it. This is likely because I never fix the issue permanently and because I don’t get the opportunity to use PowerCLI as much as I would like (I don’t have a large production environment like many of you have). So, let’s not only fix this PowerCLI execution policy error but also do it “once and for all”.
As the GUI error message said when we were installing PowerCLI, to resolve this, you simply need to set the PowerCLI execution policy to remotesigned. To do it, use the same command prompt that you see in the Window in Figure 7 and type:
Here’s what it might look like:
NOTE: If it didn’t work.. Why is that? It can be because you didn’t have access to the registry, you couldn’t set this. To set this successfully, you have to open the PowerCLI prompt as Administrator (or equivalent).
PowerGUI, VMware Community PowerPack, & Project Onyx – Must Have Tools
Now that you have the required PowerCLI installed and the correct security policy, you need the single tool that is going to make using PowerCLI easier. Using PowerCLI from that unhelpful and boring old black command window reminds me of using MS-DOS. Trust me, that’s not how you want to use PowerCLI.
The single tool that you must have to use PowerCLI productively, luckily, is completely free and comes with a ton of pre-created scripts. That tool is PowerGUI and it includes the VMware Community PowerPack. You can download it from PowerGUI.org and the install is your quick and customary Windows install process.
Resources for Learning PowerCLI
- BOOK: VMware vSpherePowerCLI Reference: Automating vSphere Administration by Luc Dekens, Alan Renouf, Glenn Sizemore, Arnim van Lieshout, & Jonathan Medd
- BOOK: Managing VMware Infrastructure with Windows PowerShell by Hal Rottenberg
- VIDEO: TrainSignal’sVMware vSpherePowerCLI Video Training by Hal Rottenberg
- If you have significant fund to spend learning PowerCLI, VMware has their official education course, VMware vSphere: Automation with vSpherePowerCLI (still at version 4.1).
- Luc Dekens - http://www.lucd.info
- Alan Renouf - http://www.virtu-al.net/
- Jonathan Medd - http://www.jonathanmedd.net/
- Hal Rottenberg - http://halr9000.com/