This content is part of the Essential Guide: Stay connected with tips and trends in vSphere networking
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

VMware PowerCLI 5.5 flexes administrative muscles

System administrators with a penchant for automating tasks with cmdlets will enjoy the heady enhancements unveiled in VMware PowerCLI 5.5.

VMworld 2013 has come and gone in both San Francisco and Barcelona. There were numerous product announcements around vSphere 5.5, VMware Virtual SAN beta, vSphere Flash Read Cache, and the enhancements to management suite vCenter Operations Manager. What didn't get a lot of hype, despite being the subject of one of the most attended VMworld sessions, was PowerCLI 5.5.

PowerCLI 5.5 brings not only support for vSphere 5.5, but some new cmdlets and features as well. For those who like to automate tasks with scripting, these upgrades will be welcome.

Using tags to organize virtual machines

The release of vSphere 5.1 in August 2012 introduced tagging, which allows an administrator to assign tags to an inventory object. Before tags, administrators used folders to help organize and identify virtual machines, but only one VM could belong to a folder. This caused some issues when trying to organize VMs based on multiple conditions.

Tags solved this issue by letting administrators assign several tags to one object or multiple objects, which are searchable through the vSphere Web Client. The problem was that vSphere 5.1 had no PowerCLI access to tags, which limited their use. The big advantage with tags is the ability to grab all of the VMs based on a certain set of tags and perform some action on them, which I would ultimately do with PowerCLI. Going into the vSphere Web Client and dumping a .csv file was not very efficient. Now we have PowerCLI 5.5 with (almost) full support for tags.

New tag enhancements and cmdlets

Let's say we had a couple of tags in our environment; one labeled NetworkStorage, which represented data stores that reside on network storage, and another labeled Accounting, which identified VMs belonging to the accounting business unit.

We get the call that the accounting department wants to perform some maintenance, which requires all of the VMs residing on Network Storage to be powered off. Utilizing the new tagging functionality, we can list data stores that are tagged with NetworkStorage using the following command:

get-datastore –tag NetworkStorage

Now, let's use piping to find VMs that have been tagged with the Accounting business unit:

get-datastore –tag NetworkStorage | get-vm –Tag Accounting

To perform a full shutdown of those VMs, we could execute the following:

get-datastore -tag NetworkStorage | get-vm -Tag Accounting | where-object {$_.PowerState -eq "PoweredOn" } | Shutdown-VMGuest

These commands show how the new tag parameters in PowerCLI allow administrators to isolate specific objects and execute actions on them. Aside from the Get-VM and Get-Datastore cmdlets, the –Tag parameter has also been added to the Get-VMHost, Get-VirtualPortGroup and Get-VDPortGroup cmdlets.

New cmdlets added to assist with tagging

Along with those tag parameters, PowerCLI also introduces some new cmdlets around tagging. The Get-Tag cmdlet displays all tags in your environment. The Get-TagAssignment, Remove-TagAssignment and New-TagAssignment cmdlets handle the retrieving, removing and assigning of tags to your inventory objects.

Let's say we had a tag that defined the physical location of our VMs, and we have just introduced a new host named esxi-01 and VMs residing in a New York location. We could tag the host and all of our inventory items on that host with the following:

Get-VMHost esxi-01 | New-TagAssignment –Tag "NewYork"

Get-VMHost esxi-01 | Get-VM | New-TagAssignment –Tag "NewYork"

Get-VMHost esxi-01 | Get-Datastore | New-TagAssignment –Tag "NewYork"

Some limitations do remain, though. We have just about everything we need to manage our tagging infrastructure with PowerCLI. But there are still some inventory objects in vCenter that do not support a -tag parameter on their corresponding Get cmdlet. Things like Get-ResourcePool, Get-Datacenter and Get-VirtualSwitch do not support passing a tag parameter. However, you can assign tags to them using New-TagAssignment. Also, there is no way to create a new tag through PowerCLI. That will have to be done through the Web Client.

Automate administration of virtual distributed switches

When VMware released PowerCLI 5.1 R2 in February 2013, the company unveiled new cmdlets to manage a vSphere Distributed Switch (vDS). These cmdlets centered around the basic functions and operations an administrator might perform on a vDS. VMware expanded vDS support in PowerCLI 5.5 with additional cmdlets that go further with management of vDSes.

Two of these new vDS-related cmdlets are Add-VDSwitchPhysicalNetworkAdapter and Add-VirtualSwitchPhysicalNetworkAdapter. These cmdlets allow an administrator to use automation to migrate physical network adapters on the hosts from vDSes to vSphere standard switches (vSwitches) and vice versa. The following example details how to migrate "vmnic2," which is currently attached to a vSwitch, to a vDS.

Get-VDSwitch Dswitch | Add-VDSwitchPhysicalNetworkAdapter -VMhostNetworkAdapter ( Get-VMhost esxi-01 | Get-VMHostNetworkAdapter -Name vmnic2)

More tools to handle distributed virtual switches

Aside from the migration of physical network adapters, PowerCLI 5.5 adds the following new cmdlets to administer distributed virtual switches.

  • Total virtual LAN management: New cmdlet Set-VDVLanConfiguration allows for distributed switch virtual LAN (VLAN) configuration. Get-VDSwitchPrivateVlan, New-VDSwitchPrivateVlan and Remove-VDSwitchPrivateVlan allow for the complete management of private VLANs.
  • Port configuration: Get-VDPort and Set-VDPort cmdlets find and modify configuration ports.
  • vDS Policy configuration: There are a slew of new cmdlets dealing with policy configuration. Things like uplink teaming, Link Aggregation Control Protocol, or LACP, port blocking, security and traffic shaping can be managed in PowerCLI 5.5.

Open up your console -- from PowerCLI

Perhaps one of the coolest new cmdlets is Open-VMConsoleWindow. As with most PowerShell cmdlets, the name doesn't leave much to the imagination; it opens a VM console window.

This cmdlet is particularly useful when you are scripting and either need to go into the guest OS to ensure changes have been applied properly, or need to manually perform some actions from within the guest OS.

Prior to Open-VMConsoleWindow, you would have had to log into the vSphere Web Client, find the VM and open a console. Now it's possible to embed the Open-VMConsoleWindow cmdlet in scripts and pass it a VM to open a browser session containing the console of the VM, just as if it was connected to it through the Web Client. The following illustrates an example of how we do that:

Open-VMConsoleWindow FreeNAS

Not only is it a very handy cmdlet to have, it's simple to use, requiring only a VM name. By passing the –UrlOnly parameter to the cmdlet, only the URL to the specified window is returned; no window is opened, but the connection information to do so is supplied. However, this may not be as convenient; due to security risk, the authentication information expires in 30 seconds.

Easier licensing procedures

Anyone who has ever attempted to assign a license key to a host knows how cumbersome the process was. It involved building and retrieving different objects from vCenter and the host, then passing those objects to API methods accessed through PowerCLI.

PowerCLI 5.5 has drastically simplified this by reducing those steps to a -LicenseHost parameter. In PowerCLI 5.5, you can assign a license to a host with the following cmdlet:

Set-VMHost esxi-01 –LicenseKey "XXXXX- XXXXX- XXXXX- XXXXX- XXXXX"

Overall, these are just a few examples of some of the big features in PowerCLI 5.5. VMware definitely seems to be listening to the PowerCLI community because many of these items were hot topics in the forums.

To get a list of all of the features, improvements and bug fixes, check out the change log for PowerCLI 5.5 here. For all the examples and functions in the new release, refer to the cmdlet reference and the official user's guide.

Dig Deeper on VMware new releases and updates

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.