PowerCLI Essentials - Chris Halverson - E-Book

PowerCLI Essentials E-Book

Chris Halverson

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Simplify and automate server administration tasks with PowerCLI

About This Book

  • Automate VMware's VSphere environment by learning the essentials of PowerCLI
  • Impress your peers by developing scripts to perform administration tasks
  • Discover the intricate workings of PowerCLI through simple and real-life examples

Who This Book Is For

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.

What You Will Learn

  • Download and install PowerCLI and its basics as well as the basics of PowerShell
  • Enchance your scritping experience
  • Build longer scripts and simpler reports
  • Relate a task in VMware administration to a PowerCLI script
  • Discover methods to acquire and change information remotely
  • Set up orchestrator to manage your workflow

In Detail

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.

Style and approach

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:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 192

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

PowerCLI Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. An Introduction to Essential Administration with PowerCLI
Why this book, and why now?
Understanding PowerShell versions
The basic structure of PowerShell
Why is version understanding important?
v2 or v3 – what's the difference?
Installing PowerShell v3 on a Windows 7 or Windows 2008 R2 machine
Understanding PowerCLI
Getting PowerCLI versions
The PowerCLI change log
Getting PowerCLI
Pre-requisites before getting PowerCLI
Downloading PowerCLI
Installing PowerCLI
Getting help
Setting up the PowerCLI installation
Summary
2. Comparing Point and Click Administration to PowerCLI and Scripting
Getting started
Where do we begin?
Where do we find scripts and snippets that are safe to run?
VMware communities
VMware blogs
VMware flings
PowerGUI
Notepad++
PowerShell Scriptomatic
Microsoft TechNet Script Center
Programming interfaces
Writing the script
Planning the purpose
Thinking through a script
Planning the output
Making the script
Final script
Report-VMHostConfigStatus
Starting with the inputs
Getting the current configuration
Output of data
Getting the same information through PowerCLI
Network
Storage
Output
Final script of the report
Summary
3. Enhancing the Scripting Experience
Code repositories – why would I need that?
Building an internal repository
Using a third-party tool for code check-in and check-out
Send it to the cloud! Publicly accessible script repositories
Conclusions
Scripting with the intention to reuse
Functions, functions, functions – the fun with functions
Example of a multifunctional script
Using modules
Calling other scripts within the script
Example of a framework script
Building a framework that others can build upon
Running a workflow
Quality control, consistency, and simplification
Revisiting documentation
Script simplification
Error handling
Verification testing
Version control and keeping previous versions
What signifies a major version versus a minor version
Storing versions
Building a VM script using all the pieces
Summary
4. Windows Administration within VMware Administration
What is DevOps?
Starting a DevOps practice
Defining the roles
An example process
Duties of the Automation Engineer
Building the script
Mixing PowerCLI and standard PowerShell
Building a Windows script host
Using commands to enable remote desktops on a Windows 2012 R2 server
Running PowerCLI and Windows Administration
A script example
Thinking through the script
Building the script
Invoke-VMScript configuration
Running remote on a Linux guest
Basic BASH
Invoke-VMScript configuration
Introduction to vRealize Orchestrator
Summary
5. Workflows and vRealize Orchestrator
Workflows
The beginning of a workflow
The planning stage
The design phase
The implementation phase
The testing phase
Promotion or closeout
vRealize Orchestrator
Architecture and history
Sample environment
Where to get it?
Prerequisites to installation
Installation
Installing the standalone instance
Configuring and integration
Summary
6. Running Workflows with Other VMware Products
Orchestrating VMware products
Orchestrating with Orchestrator
Workflows
Orchestrating the integration of NSX
NSX conceptual overview
PowerCLI and NSX
Orchestrating the integration of Site Recovery Manager
PowerCLI and SRM
Running PowerShell scripts in a Recovery Plan
Orchestrating the integration of Monitoring (vROps)
Connecting to the vRealize Operations Manager
PowerCLI and vROps
Performance tools
Orchestration of Storage (VSAN)
VSAN and PowerCLI
Summary
Index

PowerCLI Essentials

PowerCLI Essentials

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

Credits

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

About the Author

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.

About the Reviewer

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.

www.PacktPub.com

eBooks, discount offers, and more

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.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

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.

What this book covers

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.

What you need for this book

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:

A VMware vCenter server utilizing a Windows-based standalone installation or a vCenter Server ApplianceAn attached VMware ESXi server

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.

Who this book is for

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.

Conventions

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:

$PSVersionTable.PSVersion.Major

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."

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 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.

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 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:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

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 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

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.

Questions

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.

Chapter 1. An Introduction to Essential Administration with PowerCLI

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:

PowerShell versionsPowerCLI versionsGetting PowerShell and PowerCLISetting up the environmentPowerShell basics

Why this book, and why now?

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.

Understanding PowerShell versions

PowerShell, or PoSH as it is also known, is a shell scripting language that Microsoft created to replace batch and VBScript:

Version 1 was introduced in 2006, was available to be downloaded for Windows XP, Vista, or Windows Server 2003, and was an optional component of Windows Server 2008Version 2 was integrated into Windows 7 and Windows Server 2008 R2 server and was available for download for earlier versions Windows XP SP3, Vista SP1, Server 2003 SP2, and Server 2008Version 3 was included in the base version of Windows 8 and Windows Server 2012 and could be installed on Windows 7 SP1 and 2008 R2 SP1Version 4 was integrated into Windows 8.1 and Windows Server 2012 R2 and could be installed on Windows 7 SP1, Windows Server 2008 R2 SP1, and Windows Server 2012Version 5 was still public beta as of the time of writing this book and is only installable on Windows 8.1, Server 2012, and 2012 R2

The basic structure of PowerShell

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:

Get-Service –DisplayName "VMware*"Status Name DisplayName------ ---- -----------Running VMTools VMware ToolsRunning VMUSBArbService VMware USB Arbitration ServiceStopped vmvss VMware Snapshot ProviderRunning vmware-view-usbd VMware View USBRunning wsnm VMware View Client

Although, not all commands contain switches such as get-service, clarification of this topic will be discussed later in this chapter.

Why is version understanding important?

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:

$PSVersionTable.PSVersion.Major

It will produce a very brief output, as follows:

3

v2 or v3 – what's the difference?

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:

Get-VM | where {$_.Name –eq "Server"}

The same command using the v3 syntax is as follows:

Get-VM | where Name –eq Server

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?