Essential Guide

Top tools and techniques for VMware automation

A comprehensive collection of articles, videos and more, hand-picked by our editors

Time-shaving tips courtesy of vSphere PowerCLI

The book 'Learning PowerCLI' offers a basic introduction to the powerful automation tool that can shave time and reduce stress for administrators.

Whether the task is monumental or mundane, virtualization administrators can save themselves time and aggravation by automating tasks whenever possible. In a VMware environment, one of the more notable automation tools is vSphere PowerCLI.

In the book Learning PowerCLI, Robert van den Nieuwendijk gives step-by-step examples of various tasks being executed in PowerCLI, ranging from the installation of PowerCLI to the management of licenses on several hosts to make migrations less painful.

In Chapter 1 -- available online at the Packt site -- van den Nieuwendijk explains the basics behind PowerCLI, walks you through the installation process, and details the process of connecting PowerCLI to a vCenter Server or ESXi server before you can begin using cmdlets.

In one time-saving tutorial, van den Nieuwendijk describes how to store Windows session credentials in a credential store, which lets administrators avoid having to enter credentials each time they try to connect to a vCenter or ESXi server.

PowerCLI lets administrators create detailed reports, such as a list of all the VMs or all the hosts on the server. Van den Nieuwendijk explains the specific commands you can use to customize the reports, such as narrowing down by name, notes or host VM. He digs even deeper by explaining how to use wild-card characters and more.

Chapter 1 Highlights:

Before you can do useful things with PowerCLI, you have to connect to a vCenter Server or an ESXi server. And if you are finished, it is a good practice to disconnect your session. We will discuss how to do this in the following sections.

Connecting to a server

If you are not connected to a vCenter or an ESXi server, you will get an error message if you try to run a PowerCLI cmdlet. Let's try to retrieve a list of all of your datacenters using the following command:

PowerCLI C:\> Get-Datacenter

The output of the preceding command is as follows:

Get-Datacenter : 12/19/2013 7:29:36 PM    Get-Datacenter        You are not currently connected to any servers. Please connect first using a Connect cmdlet.
At line:1 char:1
+ Get-Datacenter
+ ~~~~~~~~~~~~~~
    + CategoryInfo      : ResourceUnavailable: (:) [Get-Datacenter], ViServerConnectionException

    + FullyQualifiedErrorId :Core_BaseCmdlet_NotConnectedError,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetDatacenter

You see that this gives an error message. You first have to connect to a vCenter Server or an ESXi server using the Connect-VIServer cmdlet. If you have a vCenter Server, you only need to connect to the vCenter Server and not to the individual ESXi servers.

This was last published in May 2014

Essential Guide

Top tools and techniques for VMware automation

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

How do you use vSphere PowerCLI?
Cancel

-ADS BY GOOGLE

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close