Acquisitions Editor: Agatha Kim

Development Editor: Mary Ellen Schutz, Gentle Editing LLC

Technical Editor: Stuart Radnidge

Production Editor: Eric Charbonneau

Copy Editor: Liz Welch

Editorial Manager: Pete Gaughan

Editorial Consultant: Scott Lowe

Production Manager: Tim Tate

Vice President and Executive Group Publisher: Richard Swadley

Vice President and Publisher: Neil Edde

Book Designer: Franz Baumhackl

Compositor: James D. Kramer, Happenstance Type-O-Rama

Proofreader: Rebecca Rider

Indexer: Nancy Guenther

Project Coordinator, Cover: Katie Crocker

Cover Designer: Ryan Sneed

Cover Image: © Thomas Northcut / Getty Images

Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-89079-0 (pbk)ISBN: 978-1-118-08463-2 (ebk)ISBN: 978-1-118-08465-6 (ebk)ISBN: 978-1-118-08464-9 (ebk)

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Cataloging-in-Publication Data is available from the publisher.

TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. VMware vSphere is a trademark of VMware, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

10 9 8 7 6 5 4 3 2 1

Dear Reader,

Thank you for choosing VMware vSphere PowerCLI Reference: Automating vSphere Administration. This book is part of a family of premium-quality Sybex books, all of which are written by outstanding authors who combine practical experience with a gift for teaching.

Sybex was founded in 1976. More than 30 years later, we’re still committed to producing consistently exceptional books. With each of our titles, we’re working hard to set a new standard for the industry. From the paper we print on, to the authors we work with, our goal is to bring you the best books available.

I hope you see all that reflected in these pages. I’d be very interested to hear your comments and get your feedback on how we’re doing. Feel free to let me know what you think about this or any other Sybex book by sending me an email at nedde@wiley.com. If you think you’ve found a technical error in this book, please visit http://sybex.custhelp.com. Customer feedback is critical to our efforts at Sybex.

Best regards,

Neil Edde Vice President and Publisher Sybex, an Imprint of Wiley

To my family, friends and colleagues: This took quite a bit of our time away. —Luc

For my perfect wife and children, my inspiration in life —Alan

To my Grandfather: You made me the man I am… —Glenn

To Victor, My Father, Present in Absence and therefore never Past —Arnim

For my family, for putting up with me whilst I worked on this —Jonathan

Acknowledgments

We’d all like to thank Pete Gaughan, editorial manager; Agatha Kim, acquisitions editor; Eric Charbonneau, production editor; Liz Welch, copyeditor; Nancy Guenther, indexer; Rebecca Rider, proofreader; and Jim Kramer, compositor. Without each of their contributions, this book would never have made it to the presses. In particular, we would like to thank our developmental editor, Mary Ellen Schutz, for making us all literate. Without her attention to detail, we wouldn’t have been able to produce the complete manual you’re now reading. Finally, we would like to thank Stuart Radnidge, our technical editor. Stu Rad held us all to the highest standards. He left no script unturned and no explanation unchecked. He served as the gatekeeper, ensuring that any code you find herein will run the first time, every time. (You can visit his blog by searching for vinternals from your favorite browser.) While we didn’t always see eye to eye, without the professionals at Sybex this book would never have been possible. Thanks, guys, it was a blast.

Thanks to my fellow authors and all the people at Sybex who were involved with this book. And a special thanks to “our Gentle Editor, the little old lady from Wisconsin.” She had to organize all this geek talk into the book you’re now holding in your hands. I would also like to thank all the people from VMware who produced such a great product—especially the PowerCLI Development Team in Sofia, Bulgaria, and Carter Shanklin, who made this product what it is today. Thanks also to Pablo Roesch, although we aren’t developers, we appreciate the drive with which you help us evangelize this wonderful piece of software. And finally, thanks to Jeffrey Snover and the PowerShell Team at Microsoft. Without PowerShell, none of this would have been possible. You shook the automation world!

Luc

I’d like to thank my wonderful wife and children for supporting me throughout this book and my life. To my fellow authors and everyone who has worked on this book: I would like to say thank you for staying with me and allowing me to push the boundaries time and time again. I would also like to thank my father. If he had not dragged me along to my first computer club and bought me the ZX Spectrum, I would not be here today. Thanks to my mother for her ongoing support—I know you will read this even though you don’t know what PowerShell is!

Alan

I’d like to thank my wife Kristine for marrying me in the first place. Without her support, I would not have taken on this project. To Luc and Alan: It was an honor working with you both—thank you for including me. I’d also like to thank Roger Williams and Charlie Louk; you both taught me my trade. Without your teachings, I wouldn’t be where I am today. To my fellow vExpert, co-worker, and friend: Andrew, you push me every day. Keep it up; I think it’s working!

Glenn

I’d like to thank my wife Alexandra for putting up with me and for going to bed alone many nights while I was working on this book. To my oldest son: Thank you for your patience and understanding. Yes, now I finally have time to rebuild your PC. To my middle son: Thank you for your forbearance. We now can jump on the trampoline together ’til we drop. To my newborn son: Thank you for entering my life during the process. You really gave me new inspiration.

I’d also like to thank Luc and Alan for the opportunity to realize a dream, VMware for starting the x86 virtualization revolution, the VMware PowerCLI development team for creating such a great product and finally, to all the other authors of this book: It was great working with you guys.

Arnim

I’d like to thank Alan and Luc for offering me the opportunity to be involved with the book, Alan for the remote use of his test lab, all of the authors of the book for their help and contributions, and finally the guys at Special Operations Software for suggesting in 2007 that I should learn PowerShell.

Jonathan

About the Authors

Most projects have to start somewhere as an idea, and this one was no different. Alan and I had discussed the idea of a PowerCLI book. When Sybex contacted us, our idea suddenly became a reality. As probably all first-time authors do, we horribly underestimated the effort that goes into writing a book like the one we had in mind. Luckily we had the good fortune to be able to attract some outstanding co-authors like Glenn, Arnim, and Jonathan. We hope that you, the reader, will enjoy reading this book as much as we did writing it.

Luc Dekens started many moons ago in the mainframe world as a system programmer. While the companies he worked for took Unix and Windows boxes on board, it was a natural evolution for him to expand into those areas. A couple of years ago Luc was impressed by a new scripting tool, Monad, that Microsoft was bringing to market. When the organization Luc works for was expanding their virtualization platform, he stumbled on a product called VI Toolkit. It was ideal for automating many administrative tasks. Luc was admitted to the early beta program and started contributing to the ever-growing PowerCLI community. After attending VMworld 2009 in San Francisco, where he did a session together with Hal Rottenberg, Luc started a blog (http://lucd.info). During VMworld 2010 in the US and in Europe, Luc did a session together with Alan Renouf that sold out several times.

Alan Renouf has worked in IT since 1998, starting as a junior desktop support engineer and working in a variety of IT jobs. Currently he works as a vSpecialist for EMC. Alan was named a vExpert in both 2009 and 2010. He presented a PowerCLI session with Luc Dekens at both VMworld San Francisco and Copenhagen (2010). Alan first started scripting in his childhood, copying code from magazines onto a ZX Spectrum and tweaking scripts until they worked. He worked his way through a variety of languages before settling on PowerShell. Alan is the co-host of the Get-Scripting PowerShell podcast at http://get-scripting.blogspot.com and the author of a PowerCLI-related blog at http://virtu-al.net. You can follow Alan on Twitter at http://twitter.com/alanrenouf.

Glenn Sizemore has held just about every position one could hold in IT—everything from cable dog to enterprise architect. He started scripting early in his IT career and had mastered VBScript by the time PowerShell first shipped. As a scripter, he was an early adopter and had conquered PowerShell when the VMware Toolkit for Windows (PowerCLI) first shipped. Curiosity carried Glenn to an internal team-testing virtualization. Three years later, he was attending his third VMworld and had just been awarded the status of VMware vExpert. Along the way, Glenn started a blog, www.Get-Admin.com, to share scripts and automation techniques. Outside of work, Glenn is the proud father of two beautiful children and an avid PowerShell evangelist.

Arnim van Lieshout has been in the IT industry for 12 years, working mainly with operating systems. He holds key industry certifications and recognitions from VMware, Microsoft, and Citrix. For the last 5 years Arnim has been focusing on virtualization and as a virtualization architect he has been helping enterprise customers get the most out of virtualization, especially in server consolidation and business continuity. The last few years, he has been focusing on automating tasks using PowerShell. Arnim is an active member of the VMware Community forums and is a contributor to the VMware Community PowerPack (http://vmcompack.codeplex.com/). In 2010, Arnim was awarded third place in the VMware Script-O-Mania contest and, later that year, he was designated a VMware vExpert. He runs his own blog at www.van-lieshout.com, which is focused on virtualization and utilizing PowerShell in VMware environments. You can follow Arnim on Twitter at http://twitter.com/avlieshout.

Jonathan Medd has been working with Windows Infrastructure products since 1997 and, more recently, virtualization technologies from VMware. In 2007, he discovered Windows PowerShell and now spends a lot of time encouraging IT pros he meets to use PowerShell by talking with them, giving presentations to user groups, and via posts on his blog http://jonathanmedd.net. He also co-hosts the Get-Scripting PowerShell podcast, which provides information on how to learn PowerShell and what’s going on in the PowerShell world—you can find this at http://get-scripting.blogspot.com. In April 2010, Jonathan was awarded status as a Microsoft Most Valuable Professional (MVP) for PowerShell. You can follow him on Twitter at http://twitter.com/jonathanmedd.

Foreword

2010 has been an amazing year for virtualization, the year when the number of server applications deployed as virtual machines is greater than the number deployed directly to physical hardware. The implications of this inflection point are deep, leading to significant changes in the hardware, software, and operation of modern data centers.

It’s also a time when IT budgets and resources are more squeezed than ever, and the lure of allegedly more efficient cloud computing weighs on everyone’s mind. As such, the need for great operational efficiency improvements looms large. In aiming to do even more with less, IT departments often focus substantially improving the application-to-admin ratio. Leading industry analysts estimate that the average ratio is roughly 72:1 in the virtualized world, already substantially higher than the 20:1 ratio in the physical world. This number derives very heavily from the amount of automation that an IT staff can utilize, and virtualization’s containerization and standardization of workloads helps unlock more automation than can be found in the physical world. And whether you use commercial or home-grown tools, this automation can be exploited through mature and flexible virtualization APIs and scripting capabilities.

If you find yourself repeating the same administrative task more than 3 times per week, this is the right book for you. The vSphere Automation book provides real world, hands on scenarios written by Alan Renouf and Luc Dekens. Alan and Luc are both vExperts and have worldwide reputations as the leading PowerCLI scripting authorities. The vSphere Automation Book looks at the world from the point of view of someone new to vSphere as well as someone that has been managing the vSphere platform for years.

With this book and the resources available from VMware and its user community, you will enjoy automating the tasks you have always wanted to, ultimately leading to a more stable and efficient data center. And so I wish you happy scripting, and happy virtualization!

Dr. Stephen Alan Herrod

Palo Alto, California

December 2010

Foreword

W hen asked why he robbed banks, Willie Sutton replied, “because there’s where the money is.” So when I attended the 2010 VMWorld conference and people asked me why a Distinguished Engineer from Microsoft was attending, my reply was similar, “because there’s where a big PowerShell community is.” I was delighted when I first heard about VMware’s PowerCLI and amazed to watch that community adopt PowerShell and become one of the more active centers of PowerShell scripting.

As I investigated this more, two things became clear:

1. To anyone virtualizing their IT operations, automation was the difference between success and failure.

2. It takes the right people with the right approach to transform a group of people into a thriving community.

PowerCLI had a group of people that combined a passion for PowerShell and helping other people with a very pragmatic approach to getting things done. I attended a packed session of Luc Deken’s and Alan Renouf’s PowerCLI talk and watched as most hands in the room went up when asked the question “how many of you have gotten answers to your questions in the PowerCLI community forums?” A large number of those hands stayed up when the next question was, “how many of you got that answer within a couple of minutes of asking it?”

How can you get better than that? Well you are holding the answer in your hands. Those same community superstars; Alan Renouf, Luc Dekens, Glenn Sizemore, Arnim van Lieshout and Jonathan Medd; have joined forces and produced a book codifying their collective wisdom on how to use PowerShell and PowerCLI to manage your systems. Enjoy!

Jeffrey Snover

Distinguished Engineer and Inventor of PowerShell

Introduction

This book is about automation; the title should have been a dead giveaway. More specifically, it’s about automation of your VMware vSphere environment. And, as you might have guessed from the title of the book, we automate with PowerCLI. When we were asked to write this book, one of the first decisions we made was that it had to be a practical book—a book that showed you, the reader, how to automate all the aspects of your vSphere management tasks with PowerCLI. A quick glance at the table of contents will show you that we tried to cover what we considered the most important of these management tasks. We tried to follow the same order that you, as an administrator, will encounter during the life cycle of your VMware vSphere environment.

As the saying goes, “When you do something more than once, automate it!”

Who Should Read This Book

The book is, of course, primarily targeted at administrators of vSphere environments who want to automate tasks. But the subjects that we discuss in the book cover so many aspects of the management of a VMware vSphere environment that everyone who comes into contact with a VMware vSphere environment will be able to pick up something useful.

In our day-to-day contact with PowerCLI users, we noticed that most of them start with what we like to call the reporting phase. Thanks to the natural look and feel of PowerShell and PowerCLI, it is quite easy for beginners to produce impressive reports about their vSphere environment. That’s why we included several chapters on different types of reporting. The somewhat more advanced user will go into the configuration phase. That is the moment when you start changing settings on your virtual guests and in the vSphere servers. There is an extensive number of chapters for this phase in the book.

The ultimate phase you can achieve through the use of PowerCLI is the process automation phase. As an administrator, you are now going to automate complex processes in your vSphere environment. This process can range from automating the deployment of vSphere servers all the way to automating the switch to a disaster recovery center. Again, the book offers several chapters for this phase.

Since PowerCLI runs as a snap-in in PowerShell, you might think that you have to be a Windows administrator to profit from the book. Although that is indeed the targeted audience, there are some automation aspects that are only (or at least easily) accessible through the PowerCLI snap-in. So, even if you are primarily a *nix shop, you can still profit from using PowerCLI for some of your administrative tasks.

What You Will Learn

The book shows you how you can use PowerCLI to automate your administrator tasks—not an alphabetical listing of the 250+ PowerCLI cmdlets, but a practical guide with example scripts that you can use immediately in your environment. The chapters are organized in such a way that each of them reflects a specific type of task. You probably already have done most of these tasks more than once. Now, we will show you how to automate them. In other words, you script them once and run them multiple times.

Several of the scripts we show are quite long, at least for a PowerShell script. Of course, you will not have to type them in. You will be able to download all the scripts from the book’s update page on the Sybex website at

www.sybex.com/go/vmwarevspherepowercliref

To run the scripts, you can start up the PowerCLI prompt, enter cmdlets interactively, or provide the name of the PS1 file you want to execute. Most of the scripts do not have the extensive annotations you will find on our blog posts; the book had to be a manageable size. Also, since a book has a limited page size, we often had to break single lines in our scripts over two or more lines on the printed page. The scripts that you download have the original, optimized layout.

What You Need

Software is a dynamic organism, it will have successive versions, releases, and builds. Because a book has to be published at one point in time, we aligned all our scripts and sample code on a specific set of versions. The following list contains the versions of the software we used to develop and test the scripts in this book:

VMware vSphere PowerCLI, version 4.1

VMware vCenter Server, version 4.0

VMware ESX, version 4.0

PowerShell, version 2.0

PowerGUI, version 2.2

PowerWF Studio, version 2.3

OS Platform, Windows XP Pro SP3 or higher

To know which operating systems you can use to run the PowerCLI cmdlets and scripts, you will have to look at the release notes that came with the PowerCLI build you are using.

A number of graphical environments are available that allow you to execute cmdlets and scripts. Programs like PowerGUI, PowerShellPlus, or PowerWF Studio all give you a GGI-based editor from which you can run and debug your scripts.

What Is Covered in This Book

VMware vSphere PowerCLI Reference: Automating vSphere Administration broadly follows the life cycle of your VMware vSphere environment:

Part I: Install, Configure, and Manage the vSphere Environment

Chapter 1 through Chapter 4 show you how to automate the installation and configuration of your VMware vSphere environment. They include a discussion of the vCenter Server, the ESX and ESXi servers, storage, and networking as well as some advanced vSphere features like host profiles and dvSwitches.

Chapter 1: Automating vCenter Server Deployment and Configuration takes you through some common areas automated within vSphere, starting at the beginning of the virtual infrastructure. Not only will we show you how to automate the build, but we’ll also provide examples of scripts that will help you export information into a centralized area ready for use in reports or for the import process of another setup.

Chapter 2: Automating vSphere Hypervisor Deployment and Configuration briefly walks you through the various installation methods before taking a deep dive into automating that last 10 percent. In this chapter, we will cover several techniques for streamlining the installation and configuration of vSphere.

Chapter 3: Automating Storage and Networking covers two of the most critical components of a virtual environment. Whether it’s deploying a new cluster with new storage and networking, or maintaining and upgrading existing storage and networking, automation can come to the rescue to help you save time and maintain consistency of configuration.

Chapter 4: Using Advanced vSphere Features focuses on automating some of the most advanced features vSphere offers! With the exception of the Distributed Power Management features, an Enterprise Plus license is required to utilize these features.

Part II: Managing the Virtual Machine Life Cycle

Chapter 5 through Chapter 9 tackle all the automation aspects of guests—from creating a virtual machine over linked clones and svMotion all the way to vApps. We will show you how to mass-deploy a number of guests and how to manipulate snapshots.

Chapter 5: Creating Virtual Machines explores the various methods of creating new virtual machines. Then, we will take a deep dive into the vSphere API, where we’ll cover more advanced methods and techniques. We will highlight custom attributes and their use, as well as VMware Tools installation.

Chapter 6: Using Templates and Customization Specifications covers creating templates, creating customization specifications, deploying guests, and maintaining templates over the long term. When it comes to deploying virtual machines, the tools provided are templates and customization specifications. Their use is a key part of any administrator’s game.

Chapter 7: Configuring Virtual Machine Hardware begins after your environment is all set up and running. Perhaps performance is lacking and you need to throw in an additional vCPU or more memory. Or maybe your disk is running to its maximum capacity and needs to be extended. All of these tasks and other reconfiguration tasks are covered in this chapter.

Chapter 8: Advanced Virtual Machine Features shows you how to interact with the guest operating system using the operating system’s native tools and through the PowerCLI methods. You’ll learn how to customize the scripts provided by PowerCLI to add support for Windows 7 and Windows 2008 (R2). Next, you explore how to script vMotion and Storage vMotion operations. Finally, we cover creating and maintaining snapshots.

Chapter 9: Using vApps shows you how to import virtual appliances, create your own vApps, maintain vApps, and how to simplify complex applications by providing vSphere valuable metadata about a group of VMs. You’ll learn about start order, IP pools, using IP assignments, and modifying vApp product information.

Part III: Securing Your vSphere Environment

In Chapter 10 through Chapter 13, we discuss the security aspects of your VMware vSphere environment. First, we show you how to handle backups and restores. Then, we continue with the automation of your disaster recovery. Patching and hardening of your environment conclude this part.

Chapter 10: Backing Up and Restoring Your Virtual Machines examines one of the most critical areas of any infrastructure—be it virtual or not—backup, the replication of key data to an alternate location in case of data or hardware loss.

Chapter 11: Organize Your Disaster Recovery covers designing your disaster recovery strategy. While the application server is servicing the user interface, the heart of the vCenter Server is stored in the back-end database. Learn how to back up and restore your vCenter Server database when you don’t have SQL Server Management Studio available.

Chapter 12: Hardening the vSphere Environment shows how you can use the Hardening Guides to secure your vSphere environment. First, you will see methods to access the parameters mentioned in the Hardening Guides. You’ll find a script that allows you to report the current settings. As an option, the same script can also be used to configure these settings as advised in the Hardening Guides.

Chapter 13: Maintain Security in Your vSphere Environment concentrates on host patching. Whatever operating system or application you are responsible for, it is important to keep it up-to-date. ESX(i) is no different in this respect, and VMware provides a management tool known as vCenter Update Manager (VUM) to assist with this process. We’ll introduce you to the set of PowerCLI cmdlets available for download that enable automation for VUM.

Part IV: Monitoring and Reporting

Chapter 14 through Chapter 17 show how you can automate all the reporting aspects of your VMware vSphere environment. These chapters discuss how to report on the physical hardware, virtual hardware, and the configuration parameters; how to gather statistical data for performance and capacity planning reports; how to create an audit trail; and how to monitor the environment.

Chapter 14: Reporting the Status of Your vSphere Environment shows you how to report on the most used areas of your virtual environment. When you’ve learned how to create reports and what to report on, you’ll see how to customize reports for your specific needs and how to export them into various formats.

Chapter 15: Using Statistical Data helps you obtain and analyze the built-in statistical data you need to determine how well your vSphere environment is faring over time.

Chapter 16: Monitoring the vSphere Environment helps you determine what you need to monitor and how to employ alarms in the monitoring process. Remember Murphy’s Law! To capture these unforeseen events and to react to them as fast as possible, you need to monitor your vSphere environment at all times.

Chapter 17: Auditing the vSphere Environment helps you automatically access the data required for the audit report requests that come your way. Knowing who changed what and when is useful when you are troubleshooting a problem and it is definitely required when an audit team pays you a visit.

Part V: Scripting Tools and Features

In Chapter 18 through Chapter 23, we expand on the automation scripts themselves. We’ll show you how you can schedule your scripts, how to use the methods and properties from the SDK in your scripts, and how to use Onyx to help you with the SDK methods and properties. You’ll learn how to run your scripts in graphical environments like PowerGUI and vEcoShell, and how to provide your own graphical interface for your scripts. We also introduce PowerWF Studio, a novel way to work with PowerShell and the PowerCLI snap-in.

Chapter 18: Scheduling Automation Scripts examines vCenter Server’s scheduling capabilities, helps you schedule your own scripts to run when required, and moves you closer to running a dynamic datacenter. With these scripts at your disposal, you won’t have to set your alarm to remind yourself you need to run a script.

Chapter 19: The SDK will show you how you can use the vSphere API. Now why would a book on PowerCLI bother with the vSphere API? The answer is simple. With the help of the vSphere API, your scripts can go that extra mile and perform functions that would otherwise not be available to you.

Chapter 20: The Onyx Project shows you how to use the Onyx Project to improve your understanding of the vSphere API. The Onyx Project was created by the PowerCLI Development Team to help you on your journey through the SDK.

Chapter 21: PowerGUI and vEcoShell examines two GUI automation tools that enable scripts to be presented for execution in graphical form.

Chapter 22: PowerWF Studio shows you a product that takes an original approach to using PowerShell and PowerCLI. PowerWF Studio is a Visual PowerShell development tool that provides an easy way to create powerful automation scripts using a workflow paradigm and a simple drag-and-drop interface.

Chapter 23: Add a GUI Front-End to Your Automation Scripts shows you how to use Windows forms from with PowerShell scripts. You’ll learn about PowerShell’s ties to .NET and how a .NET subset called WinForms lets you integrate Windows Forms into your scripts.

Online Bonus Content

Appendix A: Basic PowerShell examines some of the basic concepts and sets you on the road to becoming both a PowerShell and PowerCLI expert!

Appendix B: References and Links provides additional resources. Every good book leaves you wanting to know more. Here you’ll find some good places to start your search.

How to Contact the Authors

We welcome feedback from you about this book. We’ve developed a message board for everything related to the book at www.powerclibook.com. Stop by and let us know how we did, check for updates, and join the discussion. If you have specific questions, send us a message at info@powerclibook.com. You can also connect to each of us through our blogs:

Luc Dekens—LucD notes: My PowerShell Ramblings at www.lucd.info

Alan Renouf—VIRTU-AL: Virtually Everything is POSHABLE at www.virtu-al.net

Glenn Sizemore—get-admin: Lessons of a Datacenter Administrator at www.Get-Admin.com

Arnim van Lieshout—Arnim van Lieshout: About virtualization and more at www.van-lieshout.com

Jonathan Medd—Jonathan Medd’s Blog: Scripting, PowerShell, VMware, Windows, Active Directory & Exchange. All that kind of stuff… at www.jonathanmedd.net

Sybex strives to keep you supplied with the latest tools and information you need for your work. Please check the book’s update page on the Sybex website at www.sybex.com/go/vmwarevspherepowercliref. Here, we’ve posted optimized electronic copies of the scripts, batch files, and tools created for this book. We’ll post additional content and updates that supplement this book if the need arises.

Part I

Install, Configure, and Manage the vSphere Environment

Chapter 1: Automating vCenter Server Deployment and Configuration

Chapter 2: Automating vSphere Hypervisor Deployment and Configuration

Chapter 3: Automating Storage and Networking

Chapter 4: Using Advanced vSphere Features

Chapter 1

Automating vCenter Server Deployment and Configuration

In this chapter, you will learn to:

Prepare the vCenter Server Installation

Create an Automated Installation

Set Up Your vCenter Server Folder Structure

Creating a Folder Structure from Scratch

Exporting a Folder Structure

Importing a Folder Structure

Define Users and Their Privileges

Granting Privileges

Creating New Roles

Bringing in Users

Exporting Permissions

Importing Permissions

Configure Datacenters and Clusters

Creating Datacenters

Creating Clusters

Configuring High Availability

Configuring Distributed Resource Scheduler

Configuring Enhanced vMotion Compatibility

Configuring Distributed Power Management

Licensing

Viewing License Information

Licensing a Host

One of the focal points and key use cases of PowerCLI is the automation of tasks that are needed either as part of a disaster recovery (DR) solution or as part of an automated deployment solution that can be used repeatedly—You will be safe in the knowledge that the script will produce a consistent and easy-to-use solution.

This chapter will take you through some common areas automated within vSphere, starting at the beginning of the virtual infrastructure. Not only will we show you how to automate the build, but we’ll also provide examples of export scripts that will help you export information into a centralized area, the exported data will then be ready for use in reports or for the import process of another setup.

Prepare the vCenter Installation

As part of the overall virtual infrastructure, one of the first areas you will need to install is the vCenter Server, or Virtual Infrastructure Server. Although this cannot be done directly using PowerCLI cmdlets, you can use the automated nature of PowerCLI and PowerShell to automate the install of vCenter Server.

The key thing to remember while reading this chapter—and indeed the entire book—is that PowerShell reaches past the virtual infrastructure. It can be used to manage most areas of the Windows-based operating system and application set. PowerCLI is purely an addition to PowerShell (known as a snap-in) that allows you to manage the virtual infrastructure.

To automate the installation of vCenter Server and its respective components, including the vSphere Client, Update Manager, Converter, and the corresponding databases, you will need the install media as well as various other items, such as the correct version of the .NET Framework and Windows installed on the server. The components you choose to install will depend on your infrastructure and the type of database you are going to use with your vCenter Server install.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!