34,79 €
Simplify and automate server administration tasks with PowerCLI
PowerCLI Essentials is focused toward virtualization professionals and system administrators who want to discover and learn about the automation techniques associated with PowerCLI for complex virtual environments.
Have you ever wished you could automatically get a report with all the relevant information about your VMware environments in exactly the format you want? Or that you could automate a crucial task that needs to be performed on a regular basis? Powerful Command Line Interface (PowerCLI) scripts do all these things and much more for VMware environments. PowerCLI is a command-line interface tool used to automate VMware vSphere environments. It is used to handle complicated administration tasks through use of various cmdlets and scripts, which are designed to handle certain aspects of VSphere servers and to help you manage them.
This book will show you the intricacies of PowerCLI through real-life examples so that you can discover the art of PowerCLI scripting. At the start, you will be taught to download and install PowerCLI and will learn about the different versions of it. Moving further, you will be introduced to the GUI of PowerCLI and will find out how to develop single line scripts to duplicate running tasks, produce simple reports, and simplify administration. Next, you will learn about the methods available to get information remotely. Towards the end, you will be taught to set up orchestrator and build workflows in PowerShell with update manager and SRM scripts.
Each and every topic in this book is explained in a very easy-to-follow fashion with real-life, simple examples so you'll get an idea not only about working with PowerCLI, but will also get an idea about scripting.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 192
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2016
Production reference: 1210416
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-177-0
www.packtpub.com
Author
Chris Halverson
Reviewer
Tom Franken
Acquisition Editor
Divya Poojari
Content Development Editor
Onkar Wani
Technical Editor
Menza Mathew
Copy Editor
Merilyn Pereira
Project Coordinator
Bijal Patel
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Graphics
Disha Haria
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Chris Halverson is a senior consultant for VMware in the Professional Services Organization in Canada. He specializes in the full Software-Defined Data Center (SDDC) stack, architecting, designing, and deploying customer solutions. He has been active in the VMware community as a VMUG leader for the past 4 years and prides himself as an active participant in the local IT market over the past 17 years. Previous roles have allowed him to work on enterprise architecture bringing process and rigor to the administration aspect of the position and automation that made the job smarter. There is even an aspect where "I replaced myself with a small script" has been heard from him when discussing the former roles.
When Chris is not working on building the virtual community, he shares his time and energy with his tremendous wife, three boys, and one princess. Excited to spend time watching and helping them figure out life for themselves, he encourages them in their sports, through their schooling, and through their own walk of faith.
Over the past few years, Chris has also been able to achieve a dream as a second degree black belt in Tae Kwon Do, crossing off one of those bucket list items.
Chris has also acted as a book reviewer.
I want to acknowledge my family, as they supported me through this time-consuming venture. There were many times when I had to forgo doing something with them to write this book.
Also, I'd like to shout out to my good friend, Adam Wysockyj, who was instrumental in getting me through the NSX portion of the book.
And last but not least, I want to thank God for the strength to write this. There were many days when I felt exhausted and through prayer was sustained and motivated to persevere.
Tom Franken has been supporting IT infrastructures for 20 years and VMWare ESX since the 2.5 days. He has extensive experience of using PowerShell and PowerCLI to automate processes and free his weekends and holidays when IT professionals are expected to perform all the disruptive work we do.
Tom Franken also helped review Getting Started with XenDesktop® 7.x by Packt Publishing.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
VMware PowerCLI is one of the most utilized command-line interfaces for a VMware vSphere System Administrator. Covering more than 480 different functions of a vSphere system, PowerCLI and PowerShell have become one of the staples of an automation enabler in this space. Taking the viewpoint of an administrator with some experience, Essential VMware Administration with PowerCLI introduces the idea and concept of taking the beginning steps toward developing one-line commands into multi-line scripts that can be used not only by the reader but also by others within their organization.
This book is designed with the mindset of think first, design second, script next, and test last. It covers getting the tool and integrating it with other products in the VMware stack and attempts to build on the knowledge outlined from the chapter before.
Chapter 1, An Introduction to Essential Administration with PowerCLI, sets the stage through discussing how to get PowerCLI, what the difference is between PowerShell and PowerCLI, discusses its version history, and provides a starting point with its installation. This chapter is a means to get you up and running with the right version and the best tools for the job.
Chapter 2, Comparing Point and Click Administration to PowerCLI and Scripting, looks through the eye of an administrator, helping to redefine the typical point and click doldrums and compare them to the exciting and provocative world of scripting.
Chapter 3, Enhancing the Scripting Experience, takes the previous chapter and builds upon it. This chapter will enhance the experience through better practices, help a team build a repository, and make the code reusable.
Chapter 4, Windows Administration within VMware Administration, starts with the preparation of a DevOps practice and the roles around it. This programmatically helps bridge the gap for becoming operationally transformed and influences how an organization can build a private cloud type of environment. We will use this mindset to build and provision a Windows script host, and run PowerCLI and Windows-based PowerShell in the same script.
Chapter 5, Workflows and vRealize Orchestrator, introduces the vRealize Orchestrator product, how workflows are developed, and where to use them. The chapter will provide a walkthrough of the installation of vRealize Orchestrator and where it fits in the environment.
Chapter 6, Running Workflows with Other VMware Products, discusses other VMware products such as NSX, Orchestrator, vRealize Operations Manager, Site Recovery Manager, and VSAN. It takes each technology and product, explains the product, where it fits, and then, finally, how PowerCLI can integrate with them.
This book depends upon you, the reader, to have a vSphere environment to connect to and run the scripts against. This can be achieved through a try and buy download from VMware.com or with a company Test environment. A vSphere environment typically includes:
This book was written using PowerShell v3 on Windows Server 2008 R2 VM or on PowerShell v4 running on Windows Server 2012 R2 VM. The scripts were tested on multiple systems for compatibility and to reduce errata in the scripts. PowerCLI version 6.0 R1 and R2 were used.
PowerCLI Essentials is focused toward virtualization professionals and system administrators who want to discover and learn about the automation techniques associated with PowerCLI for complex virtual environments.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The Get-PowerCLIConfiguration command will show three scopes of the configuration, Session, User, and AllUsers."
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Set Screen Buffer Size for Width and Height whenever possible."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in 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 at www.packtpub.com/authors.
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.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.
You can download the code files by following these steps:
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
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 could 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 to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted 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 <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
It's 4 pm on a Friday afternoon; you are packing up for a weekend camping trip with the family when your boss walks up to your desk with that I have an immediate task that I need to hand off before I leave for the weekend look on his face. You say, "Hey sir, I am just heading out camping this weekend and I need to beat the traffic, gotta go!" But you are just not that lucky, he quickly replies that his boss has an important meeting and needs some numbers before a Monday morning meeting, and adds, "I don't have the skills in the infrastructure to get this information and I am desperate to get this tonight. Besides, we will all look like heroes if we do this." "Or at least you will", you mutter under your breath.
Is that a normal scenario in your office? It was my role for a number of clients over the last few years until I started predicting the future and writing PowerCLI scripts. This book is a collection of administration experiences for managing a virtual infrastructure and for incorporating the vast skill of DevOps and scripting.
This chapter deals with the getting started mentality, experiencing taking the System Administrator role to the next level, and making the endless job of system operations a bite-sized effort.
In this chapter, you will learn about:
System Administration has always been somewhat of a thankless job, and as an admin, making things easier and quicker has always been the end goal. Understanding the underpinnings of PowerShell and PowerCLI will help with mundane daily tasks associated with regular administration. This chapter will help you get up to speed using the command line and allow shortening of time for you to be comfortable and proficient with it.
PowerShell, or PoSH as it is also known, is a shell scripting language that Microsoft created to replace batch and VBScript:
PoSH, based on the .NET framework, establishes a structure for programming/scripting into a human-readable format. Previous Windows scripting languages were, for the most part, cryptic and it wasn't always easy to pass a script to another administrator without the other administrator having extensive experience with the language.
Originally, the Command Line Interpreter or CLI (cmd.exe or command.com) allowed the running of specific executables or EXEs through a recipe of other known commands into a batch (.bat) or command script (.cmd). These scripts were used to build a setup for users (such as login scripts) or to launch a customized experience for an application startup or application installation.
The cscript.exe command enabled the inclusion of JavaScript or VBScript in the recipe and gave an administrator much more power to do far more complex and useful tools. The script was written with an external program (notepad.exe, for example) and then the cscript.exe command would have to precede the script.
After Microsoft's previous attempts at power and user friendliness, PoSH follows a basic human readable format of Verb-Noun for commands to be written. Get-Service, for example, uses the verb Get and the noun Service to specify the desire to get what services are running. Switches such as DisplayName can add to the clarity of the command and shorten the output:
Although, not all commands contain switches such as get-service, clarification of this topic will be discussed later in this chapter.
As a typical System Administrator of multiple systems, it is likely that PoSH has been used due to newer Microsoft systems' (Exchange, SQL, or basic Windows admin functions) requirements for administration. With every version increment, additional features get added to the product, such as syntax simplification and additional cmdlets (pronounced command-let); this provides more functionality and script simplification possibilities to ensure certain version baselines in the environment allow single source scripts and common programming specifications.
To simplify, using the newest version available allows more functionality and ease of use. To use an analogy of buying a car, getting a newer car generally provides more features, performance, and gadgets. The manufacturer learns from the shortcomings of previous years and makes a better product.
Many companies use a plethora of Windows servers and Windows desktops to support their business's attempt at maintaining a standard platform for operating, deployment, and implementation to reduce the amount of work. In most environments, there are a variety of server versions in place, from Windows Server 2003 to Windows Server 2012 R2, all supporting different applications and being supported by hundreds of vendors. Each iteration of the Server product may, and typically does, have a variety of components that need to be maintained, such as Windows Patches, and in the case of VMware Infrastructure, VMware Tools and Hardware versions (Drivers).
As seen in the Understanding the PowerShell versions section, there are five listed versions available. Of these, version 2 (v2) and version 3 (v3) apply the greatest variance amongst all of the versions. Programming scripts using the v3 syntax will produce errors in v2, whereas v2 syntax will work in v3. Microsoft provides a much simpler experience using the newer versions, and all scripts within this book will be written using v3 unless otherwise stated.
Thankfully, there is a simple way to test what version of the Windows OS is running. To find out the current version of PoSH, type this command:
It will produce a very brief output, as follows:
Is there a difference? There are quite a few variations between the two, but a single key differentiator shown here highlights it.
A basic one-line v2 command is as follows:
The same command using the v3 syntax is as follows:
At first glance, the differences are apparent. v2 demands additional brackets, quotes and variable definitions to make the command work, whereas, v3 removes the cryptic demands and simplifies the command string. With v3, it is backwards compatible, so PoSH v2 commands will also work within the v3 command structure.
One of the significant additions to v3 is the inclusion of workflows. Workflows allow the running of multiple scripts in a cascading fashion. This provides a means to develop the ability to write recipes with many parts into a single consistent plan. This can be extremely powerful and useful and is discussed in later chapters.
So the question that begs to be asked is: Why not develop all code within the context of v2?
