Book Image

Learning PowerCLI for VMware VSphere

By : Robert van den Nieuwendijk
Book Image

Learning PowerCLI for VMware VSphere

By: Robert van den Nieuwendijk

Overview of this book

Table of Contents (17 chapters)
Learning PowerCLI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

VMware vSphere PowerCLI is a command-line automation and scripting tool that provides a Windows PowerShell interface to the VMware vSphere and vCloud products.

Learning PowerCLI shows you how to install and use PowerCLI to automate the management of your VMware vSphere environment. With lots of examples, this book will teach you how to manage vSphere from the command line and how to create advanced PowerCLI scripts.

What this book covers

Chapter 1, Introduction to PowerCLI, gets you started using PowerCLI. First, you will see how to download and install PowerCLI. Then, you will learn to connect to and disconnect from the vCenter and ESXi servers and retrieve a list of all of your hosts and virtual machines.

Chapter 2, Learning Basic PowerCLI Concepts, introduces the Get-Help, Get-Command, and Get-Member cmdlets. It explains the difference between PowerShell Providers and PSDrives. You will see how you can use the raw vSphere API objects from PowerCLI and how to use the New-VIProperty cmdlet to extend a PowerCLI object.

Chapter 3, Working with Objects in PowerShell, concentrates on objects, properties, and methods. This chapter shows how you can use the pipeline to use the output of one command as the input of another command. You will learn how to use the PowerShell object cmdlets and how to create your own PowerShell objects.

Chapter 4, Managing vSphere Hosts with PowerCLI, covers the management of the vSphere ESXi servers. You will see how to add hosts to the vCenter server and how to remove them. You will work with host profiles, host services, Image Builder, and Auto Deploy, as well as with the esxcli command and the vSphere CLI commands from PowerCLI.

Chapter 5, Managing Virtual Machines with PowerCLI, examines the lifecycle of virtual machines—from creating to removing them. Creating templates, updating VMware Tools and upgrading virtual hardware, running commands in the guest OS, and configuring fault tolerance are some of the topics discussed in this chapter.

Chapter 6, Managing Virtual Networks with PowerCLI, walks you through vSphere Standard Switches and vSphere Distributed Switches, port groups, and network adapters. It shows you how to configure host networking and how to configure the network of a virtual machine.

Chapter 7, Managing Storage with PowerCLI, explores creating and removing datastores and Datastore Clusters, working with Raw Device Mapping, configuring software iSCSI initiators, Storage I/O Control, and Storage DRS.

Chapter 8, Managing High Availability and Clustering with PowerCLI, covers HA and DRS clusters, DRS rules and DRS groups, resource pools, and Distributed Power Management.

Chapter 9, Managing vCenter with PowerCLI, shows you how to work with privileges, work with roles and permissions, manage licenses, configure alarm definitions, alarm action triggers, and retrieve events.

Chapter 10, Reporting with PowerCLI, concentrates on retrieving log files and log bundles, performance reporting, exporting reports to CSV files, generating HTML reports, sending reports by e-mail, and reporting the health of your vSphere environment with the vCheck script.

What you need for this book

To run the example PowerCLI scripts given in this book, you need the following software:

  • VMware vSphere PowerCLI

  • Windows PowerShell 2.0 or Windows PowerShell 3.0

  • VMware vCenter Server

  • VMware ESXi

The scripts in this book are tested using VMware vSphere PowerCLI 5.5 Release 1, VMware vCenter Server 5.5, and VMware ESXi 5.5.

Windows PowerShell and VMware vSphere PowerCLI are free. You can download a free 60-day evaluation of VMware vCenter Server and VMware ESXi from the VMware website. It is not possible to modify the settings on the free VMware vSphere Hypervisor using PowerCLI.

Who this book is for

This book is written for VMware vSphere administrators who want to automate their vSphere environment using PowerCLI. It is assumed that you have at least a basic knowledge of VMware vSphere. If you are not a vSphere administrator, but you are interested in learning more about PowerCLI, then this book will also give you some basic knowledge of vSphere.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The –Name parameter is required."

A block of code is set as follows:

$Cluster = Get-Cluster –Name Cluster01
New-VM –Name VM1 –ResourcePool $Cluster

Any command-line input or output is written as follows:

PowerCLI C:\> New-VM –Name VM1 –ResourcePool (Get-Cluster –Name Cluster01)

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.