This content is part of the Essential Guide: Enable VMware automation with these top tools and techniques

Mastering PowerCLI commands to control VMware vCloud and vSphere

VMware tools increasingly abstract the admin from the underlying virtual infrastructure. To retain granular control, buff up on PowerCLI commands.

With VMware increasingly abstracting the data center from the administrator's granular control, the command line interface remains a bastion for administrators that want a hairy eyeball and an iron grip on exactly what's going on in their environment.

For VMware administrators reaching for scripts and CLIs more often, a few free resources will help write better commands and catch errors.

Most VMware admins that go in for scripting are using PowerCLI, a Windows PowerShell snap-in for managing vSphere. PowerCLI 5.1 aims to make scripts easier to write -- and review -- with the simplified syntax of PowerShell 3.0. The syntax is supposed to make command lines read more like a line of human language and less like code.

The PowerCLI user community is active and not shy about sharing what they've come up with to automate common tasks. Whether you're browsing for a completed script that meets your needs or building up a library from which you can write scripts, keep blogs and wikis on your radar. Community-contributed wikis like this one on SHIFT are good repositories of scripts to check before writing your own. Luke Huckaba, virtualization engineer at Rackspace and blogger at, maintains a file of PowerShell scripting terms on his blog, including VMware's PowerCLI cmdlets.

VMware's cloud computing push has led to new scripts. PowerCLI 5.1 introduced vCloud Director 5.1 management via the command line, as well as support for VMware virtual distributed switches. With the abstraction layer introduced by VMware's vCloud Director, admins might find themselves turning to PowerCLI to hunt down VMs and otherwise get granular in the infrastructure. Jake Robinson, engineer at BlueLock and blogger at GeekAfterFive, has spent considerable time working with vCloud via the PowerCLI interface. Check out his scripts for finding a VM's information in a vCloud vApp and other actions.

When creating command prompts for PowerCLI, XML skills can save IT pros a lot of time and energy. PowerShell offers a bounty of PowerCLI cmdlets, such as Get-VDSwitch, that are the basis of scripts written with XML. "There are plenty of horror stories around using XML," said Dan Stolts, an IT consultant and Microsoft IT pro evangelist. "Mess up your tags, and you can end up corrupting the database." For example, if you don't open and close XML tags in the proper order, PowerCLI could do something you never intended, even though it's following your script. But don't let that scare you away. Stolts, presenting at a New England VTUG 2013 meeting, recommended notepad++, a free, easy-to-read manual source code editor. With color-coded text, the XML-based script is well organized, limiting the potential for human error during editing. After all, command line tools are like a chainsaw, as contributor Alastair Cooke likes to say, because they can speed up a job and destroy a job, depending on your ability to use them.

Dig Deeper on Scripting administrative tasks