PowerCLI Cookbook - Philip Sellers - E-Book

PowerCLI Cookbook E-Book

Philip Sellers

0,0
39,59 €

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

Mehr erfahren.
Beschreibung

If you are a virtualization professional who wants to unleash the power of automation and combat the complexity of sprawling virtual environments, this book is ideal for you. This book will enhance your skills of administering VMware vSphere and vCloud Director with PowerCLI.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 442

Veröffentlichungsjahr: 2015

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 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Instant updates on new Packt books
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. Configuring the Basic Settings of an ESXi Host with PowerCLI
Introduction
Connecting to an ESXi host or a vCenter instance
Getting ready
How to do it...
How it works…
There's more…
See also
Getting the VMware host object
Getting ready
How to do it...
How it works…
There's more…
See also
Joining an ESXi host into Active Directory
Getting ready
How to do it...
How it works…
There's more…
See also
Enabling services and setting security profiles
Getting ready
How to do it…
How it works…
There's more…
Setting network configuration
Getting ready
How to do it...
How it works…
There's more…
See also
Creating datastores on an ESXi host
Getting ready
How to do it…
How it works…
See also
Configuring syslog settings on an ESXi host
Getting ready
How to do it…
How it works…
There's more…
Joining an ESXi host to vCenter
Getting ready
How to do it…
How it works…
See also
Creating a configuration script to set all properties uniformly
Getting ready
How to do it…
How it works…
See also
2. Configuring vCenter and Computing Clusters
Introduction
Creating a virtual datacenter in vCenter
Getting ready
How to do it…
How it works…
Creating a cluster and adding ESXi hosts
Getting ready
How to do it…
How it works…
There's more…
See also
Setting cluster advanced features, including HA, DRS, and EVC
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up resource pools
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up folders to organize objects in vCenter
Getting ready
How to do it…
How it works…
There's more…
See also
Setting permissions on vCenter objects
Getting ready
How to do it…
How it works…
There's more…
3. Managing Virtual Machines
Introduction
Deploying the first virtual machine
Getting Started
How to do it…
How it works…
There's more…
See also
Cloning a virtual machine to a template
Getting Started
How to do it…
How it works…
There's more…
See also
Deploying new virtual machines from a template
Getting Started
How to do it…
How it works…
There's more…
Importing a virtual appliance from OVA
Getting Started
How to do it…
How it works…
There's more…
See also
Performing a hot add of virtual hardware to an existing virtual machine
Getting Started
How to do it…
How it works…
There's more…
See also
Enabling and disabling Fault Tolerance on a virtual machine
Getting Started
How to do it…
How it works…
See also
Increasing the disk space in a virtual machine
Getting Started
How to do it…
How it works…
Upgrading the virtual hardware version of a virtual machine
Getting Started
How to do it…
How it works…
See also
Locating and reloading inaccessible or invalid virtual machines
Getting Started
How to do it…
How it works…
Setting VMware Tool settings from PowerCLI
Getting Started
How to do it…
How it works…
Creating basic reports of VM properties using VMware Tools and PowerCLI
Getting Started
How to do it…
How it works…
There's more…
See also
4. Working with Datastores and Datastore Clusters
Introduction
Performing Storage vMotion
Getting ready
How to do it…
How it works…
There's more…
Finding Raw Disk Mappings in your environment
Getting ready
How to do it…
How it works…
There's more…
See also
Locating thin or thick provisioned disks
Getting ready
How to do it…
How it works…
There's more…
Converting thin to thick disks with Storage vMotion
Getting ready
How to do it…
How it works…
There's more…
Creating and managing datastore clusters
Getting ready
How to do it…
How it works…
Setting Storage DRS automation levels for individual virtual machines
Getting ready
How to do it…
How it works…
There's more…
Setting Storage DRS automation levels for individual VMs using PowerCLI 6
Getting ready
How to do it…
How it works…
5. Creating and Managing Snapshots
Introduction
Creating a snapshot
Getting Started
How to do it…
How it works…
There's more…
See also
Getting a list of snapshots in the environment
Getting Started
How to do it…
How it works…
There's more…
Manipulating the list of snapshots to get better information
Getting Started
How to do it…
How it works…
There's more…
See also

Scoping and filtering a list of snapshots
Getting Started
How to do it…
How it works…
There's more…
Removing targeted snapshots
Getting Started
How to do it…
How it works…
There's more…
Find lost or unknown snapshots
Getting Started
How to do it…
How it works…
Creating a function to automatically remediate snapshots
Getting Started
How to do it…
How it works…
There's more…
See also
Scheduling automatic snapshot remediation
Getting Started
How to do it…
How it works…
See also
Creating a snapshot management module
Getting Started
How to do it…
How it works…
There's more…
6. Managing Resource Pools, Reservations, and Limits for Virtual Machines
Introduction
Setting reservations and limits for resource pools
Getting ready
How to do it…
How it works…
There's more…
See also
Balancing share allocations on resource pools
Getting ready
How to do it…
How it works…
There's more…
See also
Creating a custom attribute with a number of shares per VM on each resource pool
Getting ready
How to do it…
How it works…
Automating share allocation balancing
Getting ready
How to do it…
How it works…
There's more…
See also
Reporting shares, reservations, and limits of resource pools and virtual machines
Getting ready
How to do it…
How it works…
There's more…
See also
7. Creating Custom Reports and Notifications for vSphere
Introduction
Getting alerts from a vSphere environment
Getting ready
How to do it…
How it works…
There's more…
See also
Basics of formatting output from PowerShell objects
Getting ready
How to do it…
How it works…
There's more…
See also
Sending output to CSV and HTML
Getting ready
How to do it…
How it works…
There's more…
Reporting VM objects created during a predefined time period from VI Events object
Getting ready
How to do it…
How it works…
There's more…
See also
Setting custom properties to add useful context to your virtual machines
Getting ready
How to do it…
How it works…
There's more…
See also
Using PowerShell native capabilities to schedule scripts
Getting ready
How to do it…
How it works…
There's more…
See also
8. Performing ESXCLI and in-guest Commands from PowerCLI
Introduction
Retrieving the ESXCLI object in PowerCLI
Getting ready
How to do it…
How it works…
There's more...
Using the ESXCLI vm namespace to kill a misbehaving VM
Getting ready
How to do it…
How it works…
There's more…
Performing ESXi ping with an ESXCLI object
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring custom storage and path selection policies
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring coredump settings for an ESXi host from PowerCLI
Getting ready
How to do it…
How it works…
There's more…
See also
Executing native commands inside the guest operating system from PowerCLI
Getting ready
How to do it…
How it works…
There's more…
See also
9. Managing DRS and Affinity Groups using PowerCLI
Introduction
Applying recommendations for partially automated DRS clusters
Getting ready
How to do it…
How it works…
There's more…
See also
Setting a cluster into maintenance mode with PowerCLI
Getting ready
How to do it...
There's more...
Using native DRS rule cmdlets to manage KeepTogether and Separate rules
Getting ready
How to do it…
How it works…
Learning the MoRef way of identifying objects
Getting ready
How to do it…
How it works…
There's more…
Creating a DRS group for virtual machines
Getting ready
How to do it…
How it works…
There's more…
See also
Listing the members of a DRS group
Getting ready
How to do it…
How it works…
There's more…
See also
Updating the members of a VM DRS group
Getting ready
How to do it…
How it works…
Creating a custom function to update members of a DRS group
Getting ready
How to do it…
How it works…
There's more…
See also
Creating rules to maintain memberships of DRS groups using a custom function
Getting ready
How to do it…
How it works…
There's more…
See also
Using Compare-Object to audit group memberships for differences
Getting ready
How to do it…
How it works…
See also
10. Working with vCloud Director from PowerCLI
Introduction
Connecting to a vCloud environment
Getting ready
How to do it…
How it works…
There's more…
Creating and managing organizations in vCloud
Getting ready
How to do it…
How it works…
There's more…
Creating a new user in an organization using Views
Getting ready
How to do it…
How it works…
See also
Creating an organization's virtual datacenter in vCloud Director
Getting ready
How to do it…
How it works…
Importing a vApp template into vCloud
Getting ready
How to do it…
How it works…
There's more…
Configuring networking in a vCloud vApp
Getting ready
How to do it…
How it works…
Reassigning vApp VM network settings with PowerCLI
Getting ready
How to do it…
How it works…
There's more…
Starting and stopping vApps and individual VMs in a vCloud
Getting ready
How to do it…
How it works…
A. Setting up and Configuring vCloud Director
The hosted vCloud environment
Deploying the vCloud Director environment from AutoLab
Build your own vCloud Director implementation on your vSphere lab environment
Additional resources
Index

PowerCLI Cookbook

PowerCLI Cookbook

Copyright © 2015 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: March 2015

Production reference: 1200315

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-372-4

www.packtpub.com

Credits

Author

Philip Sellers

Reviewers

Dustin Lenz

Ajeet Singh Raina

Earl Waud

Commissioning Editor

Ashwin Nair

Acquisition Editor

Sonali Vernekar

Content Development Editor

Arwa Manasawala

Technical Editor

Menza Mathew

Copy Editor

Rashmi Sawant

Project Coordinator

Danuta Jones

Proofreaders

Simran Bhogal

Joel T. Johnson

Indexer

Rekha Nair

Graphics

Abhinash Sahu

Production Coordinator

Melwyn D'sa

Cover Work

Melwyn D'sa

About the Author

Philip Sellers is an IT enthusiast residing in Myrtle Beach, South Carolina. Philip has more than 16 years of industry experience in consulting and systems administration. Currently, he is a senior-level systems administrator with Horry Telephone Cooperative, America's largest telecommunications cooperative. Philip focuses on Microsoft and VMware software solutions along with server and SAN infrastructure. He spends a lot of time wrangling unwieldy systems and tries to tame as much as he can with automation using tools such as PowerCLI.

Philip has a bachelor of science degree in interdisciplinary studies with a minor in computer science from Coastal Carolina University and holds certifications as a VMware VCAP5-DCA and VCP5-DCV and is a Microsoft Certified IT Professional.

He maintains a technology blog at http://www.techazine.com that provides explanations and reviews of enterprise IT solutions, and he is a leader with the Myrtle Beach VMware Users Group. You may also follow him on Twitter @pbsellers.

Philip is married to his college sweetheart, Jennifer, and has two kids who keep him busy when he's not working.

Acknowledgments

I would like to thank my wonderful wife, Jennifer, for her support and patience during the project and for all of her enthusiasm and encouragement. I enjoy every day of our adventure together. I would also like to thank my children, Peyton and Jake. No dream is too big for you to dream and if you put your mind to it, step by step (or chapter by chapter) you can achieve anything you set your mind to. You three are the reasons why I do what I do and I love you all.

To my mom and dad, thank you for always supporting me, listening, and encouraging me, no matter how crazy the idea was. Thank you dad for teaching me to troubleshoot; you prepared me in ways you'll never know because you taught me to solve problems.

A special thanks to my technical reviewers; I appreciate the valuable work you did. All of your notes and suggestions helped make this book the best possible resource it could be. Thank you to the Packt Publishing team who worked on this book. Thank you to my managers and executive staff at Horry Telephone Cooperative for allowing me to pursue this opportunity.

About the Reviewers

Dustin Lenz is currently an MTS IT systems engineer with a large semiconductor manufacturer. Dustin earned a bachelor of science degree in computer technology from Ball State University, Muncie, Indiana, and has earned his certification, VCP, from VMware for datacenter technologies.

Ajeet Singh Raina is a senior systems engineer at Dell R&D. He has received a certification in VMware Certified Professional (VCP 4.1) and has more than 7 years of experience working on open source and virtualization platforms. He was a part of the VMQA GOS Validation Team at VMware India and validated all flavors of operating systems on ESXi 4.1 and 5.0. He is currently working with Enterprise Solutions Group at Dell and has a solid understanding of a diverse range of IT infrastructure, systems management, systems integration, and quality assurance.

Ajeet has a great passion for open source technologies (Linux, Hadoop, and OpenStack). He likes providing tech-talks and technical consultations on the latest open source software and has a habit of sharing it through blogs and wikis. He can be reached at http://collabnix.com

This book would not have been a success without the direct and indirect help from many people. Thanks to my wife and my 5-year-old kid for putting up with me for all the missing family time and for providing me with love and encouragement throughout the writing period. Thanks to my parents and family members for all the love, guidance, and encouragement during the tough times.

Thanks to all my past and present colleagues and mentors at VMware and Dell for the insightful discussions and the knowledge they shared with me.

Earl Waud is a virtualization development professional with more than 7 years of focused industry experience in creating innovative solutions for hypervisor provisioning, management, and automation. He is an expert in aligning engineering strategy with organizational vision and goals, and delivering highly scalable and user friendly virtualization environments.

With more than 18 years of experience in developing customer facing and corporate IT software solutions, he has a proven track record of delivering high-caliber and on-time technology solutions that have a significant impact on business results.

Earl currently lives in San Diego, California. He is blessed with a beautiful wife, Patti, and three amazing daughters, Madison, Daniella, and Alexis.

Currently, Earl is a senior systems engineer with Intuit Inc., a company that creates business and financial management solutions that simplify the business of life for small businesses, consumers, and accounting professionals.

Earl can be reached online at http://sandiegoearl.com.

I would like to thank my wonderful family for allowing me to spend some of my precious family time to review this book. I love and appreciate you all, and I know I am truly blessed to be part of this family.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit http://www.PacktPub.com.

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

Free access for Packt account holders

If you have an account with Packt at http://www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Instant updates on new Packt books

Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.

Preface

VMware PowerCLI offers a compelling command-line alternative to the point-and-click administration of vSphere and vCloud Director. As virtualization has become mainstream and deployments begin to sprawl, the simple commands of PowerCLI allows faster administration by executing tasks on groups of objects in the virtual environment.

Since PowerCLI follows a very logical pattern, it can be quickly adopted, making it the first choice for many vSphere administrators. However, with simplicity, it also combines extensibility to allow users to build their own functions and modules to solve specific problems not addressed by out-of-box functionalities.

What this book covers

Chapter 1, Configuring the Basic Settings of an ESXi Host with PowerCLI, covers the configuration of a fresh installation of VMware ESXi on a host system.

Chapter 2, Configuring vCenter and Computing Clusters, teaches you how to perform a basic vCenter configuration and add multiple ESXi hosts into a cluster with vSphere features, such as Dynamic Resource Scheduler (DRS) and High Availability (HA).

Chapter 3, Managing Virtual Machines, provides you with many of the common tasks needed to manage virtual machines from PowerCLI, including deploying and cloning virtual machines, changing hardware settings on virtual machines, and reloading inaccessible virtual machines in vCenter.

Chapter 4, Working with Datastores and Datastore Clusters, introduces the PowerCLI cmdlets needed to create and manage datastores and datastore clusters for individual ESXi hosts or vSphere clusters.

Chapter 5, Creating and Managing Snapshots, covers cmdlets and routines to work with snapshots on virtual machines, how to manage and report on snapshots before they become problems, and uses the topic to teach you how to write your own function in PowerCLI that can be reused easily. This chapter also covers how to take your code and schedule it to run with defined triggers using native PowerShell commands.

Chapter 6, Managing Resource Pools, Reservations, and Limits for Virtual Machines, covers the topic of creating and managing resource pools and their associated settings that include reservations and limits both at a pool and virtual machine level.

Chapter 7, Creating Custom Reports and Notifications for vSphere, teaches you how to use many of the native PowerShell features for reporting and leveraging those with PowerCLI cmdlets to create custom reports and notifications.

Chapter 8, Performing ESXCLI and in-guest Commands from PowerCLI, works with the advanced topics of using ESXCLI, an alternative command-line administration tool, from within PowerCLI to access and manage settings that are not natively accessible from PowerCLI. This chapter also covers some of the basics of performing in-guest commands invoked from PowerCLI.

Chapter 9, Managing DRS and Affinity Groups PowerCLI, is built on everything covered in the previous chapters to discuss managing the vSphere DRS features from PowerCLI by building your own functions and modules to alter the group memberships of DRS groups and keep the membership updated per defined rules.

Chapter 10, Working with vCloud Director from PowerCLI, changes gears and covers managing vCloud Director and vCloud deployments in multi-tenanted environments.

Appendix, Setting up and Configuring vCloud Director, covers certain installation tips and techniques.

What you need for this book

To create and perform the commands created in the recipes of this cookbook, you will need:

VMware vSphere PowerCLIWindows PowerShell 2.0 or 3.0VMware vCenter ServerVMware ESXi hosts (physical or nested virtual)VMware vCloud Director and vShield Manager

This book was written and tested against PowerCLI versions 5.5, 5.8, and 6.0, and utilizes PowerShell 3.0.

Windows PowerShell 2.0 or 3.0 are distributed as part of the Windows Management Framework and are available for free from http://www.microsoft.com. VMware vSphere PowerCLI and the VMware Hypervisor (ESXi) are available for free from http://www.vmware.com. You can obtain a 60-day trial license for vSphere that cover ESXi and vCenter Server in order to enable advanced features and management. vCloud Director is available as a trial with a streamlined virtual appliance for evaluation purposes from http://www.vmware.com.

Who this book is for

This book is written for readers with a basic, working knowledge of PowerCLI, a command-line tool for managing vSphere and vCloud environments that is based on PowerShell. The book is written in a recipe format, which means that each chapter approaches a topic of vSphere or vCloud administration and walks you through step-by-step commands to handle the common tasks. Each recipe is built on the previous recipes that allow you to learn how to take basic commands and combine them into functions and modules in order to automate tasks for your environment, making your job easier.

It is assumed that you have a working understanding of VMware vSphere, both ESXi and vCenter Server, and the experience with vCloud Director might help you with the chapter focused on this topic. The book is written so that you can go beyond simple commands in PowerCLI and unleash the potential of more complex series of commands that handle real work problems. It is impossible to cover every possible use for PowerCLI, but the book covers some topics in representative ways and gives you techniques to apply to any other need you might encounter.

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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To check the version you are running, open a PowerCLI prompt and run Get-PowerCLIVersion."

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

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false

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: "Open the Organizations section under Manage & Monitor and select an organization."

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 <[email protected]>, 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 <[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

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

Chapter 1. Configuring the Basic Settings of an ESXi Host with PowerCLI

In this chapter, you will cover the following recipes:

Connecting to an ESXi host or a vCenter instanceGetting the VMware host objectJoining an ESXi host into Active DirectoryEnabling services and setting security profilesSetting network configurationCreating datastores on an ESXi hostConfiguring syslog settings on a hostJoining an ESXi host to vCenterCreating a configuration script to set all properties uniformly

Introduction

Initially, automation doesn't save time. To get the benefits of automation, you must invest the time upfront to create scripts that you'll use time and again. In this chapter, you'll take your first ESXi host that has been installed with an IP address configured on it, and you will configure the server continually from there. This chapter will take an administrator through the basic configuration tasks needed to perform the initial configuration, join them to vCenter, and get it into an operational state. At the end of this chapter, all of these steps will build into a scripted configuration that can be executed against new hosts in the future.

Connecting to an ESXi host or a vCenter instance

To begin working with PowerCLI, you must first have PowerShell installed and available on the system on which you will run PowerCLI. PowerShell is a part of the Windows Management Framework and it ships with Windows client and server versions. PowerCLI extends PowerShell with commands to administer VMware environments. With PowerShell installed, you will need to obtain PowerCLI from http://www.vmware.com. The specific link is listed in the See also section of this recipe.

Once you have installed PowerCLI, you will need to build an ESXi host for this recipe. All that is required is a fresh ESXi installation from the ISO or DVD image distributed by VMware. Once installed, set an IP address on an accessible network using the console screens of the new ESXi host. The network address should be accessible from your PowerCLI workstation.

With the assumption that your ESXi host is built, the first step to administer VMware environments in PowerCLI is to connect to the ESXi host or to a vCenter server. In this chapter, you will focus on how to configure a single ESXi host. In the next chapter, you will focus on how to configure a vCenter Server and a vSphere cluster of ESXi hosts.

Getting ready

To begin, you only need to launch PowerCLI from its shortcut on the desktop or from the Start Menu. If you already had PowerCLI previously installed, you will want to check the version number to ensure that the cmdlet references throughout the book are available to you. Each version of PowerCLI builds additional native cmdlets and functionalities. To check the version you are running, open a PowerCLI prompt and run Get-PowerCLIVersion.

The recipes in this book are built and tested using VMware PowerCLI 5.5 Release 1 and have also been tested with VMware PowerCLI 5.8 Release 1, which accompanies vCloud Suite 5.8. The recipes also work on vSphere and PowerCLI 6.0 with any differences noted.

How to do it...

At the PowerCLI prompt, you will execute the Connect-VIServer cmdlet as follows:
Connect-viserver <hostname or IP>
When executed, the code will attempt to perform a single sign-on into the ESXi host, but unless your username is root and you set the same password locally and on ESX, single sign-in will fail. You will be prompted with a normal Windows login window, which is displayed as follows, and you should log in with the root username and the password you specified during your ESXi installation:Once you successfully log in to the ESXi host, a confirmation message will be displayed with the name or IP address of the ESXi host you connected to, the port, and the user you've connected to, as shown in the following example:
Name Port User---- ---- ----192.168.0.241 443 root
At this point, the PowerCLI session is connected to a host and ready to execute work.

How it works…

The Connect-VIServer cmdlet is the simplest kind of cmdlet in PowerCLI. This cmdlet initiates a connection to the vCenter or ESXi web services to allow additional commands to be passed to the server and be executed.

The Connect-VIServer cmdlet requires only the name of the host to which you want to connect. There are additional parameters that you might pass to the cmdlet, such as the protocol (HTTP or HTTPS), the username, and the password. If you prefer not to keep your password in plain text, you can also pass a PSCredentials object. The PSCredentials object contains login data to authenticate. For more information about the PSCredentials objects, type get-help about_server_authentication.

Once you execute the cmdlet, a warning will be displayed in yellow, similar to the following one:

The warning is displayed because the certificate installed on the ESXi host is self-signed and untrusted by the computer you are connecting from. Changing an SSL certificate on ESXi hosts will be covered later in the book, but the warning can be ignored this time. The cmdlet will continue to execute even though the warning is displayed.

You can also prevent the invalid certificate errors by running the following PowerCLI cmdlet that changes the action when an invalid certificate is encountered:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false

There's more…

If you choose to join the ESXi host to Active Directory, your PowerCLI session performs a single sign-in. PowerCLI uses the credentials of your current Windows session to log in against the ESXi host or vCenter server if your account has access to the server. If your account does not have access to the server that it is attempting to connect to, a login box will be presented like our example, shown in the preceding screenshot, in this recipe.

See also

The Joining an ESXi host into Active Directory recipeThe Setting permissions on vCenter objects recipe in Chapter 2, Configuring vCenter and Computing ClustersVMware PowerCLI Documentation Center and Installation Download https://www.vmware.com/support/developer/PowerCLI/

Setting network configuration

One of the first things to be completed against a new ESXi installation is network configuration. Network configuration consists of several things on an ESXi host—first would be to configure the additional management interfaces of the host for VMotion, Fault Tolerance logging, vSphere Replication, and VSAN traffic.

Getting ready

To begin this recipe, you will need to open a PowerCLI window, connect to an ESXi host, and load a VMHost object into a variable. The example uses $esxihost as the variable for the VMHost object.

On installation, ESXi has a single Network Interface Card (NIC) labeled eth0 that is connected to a VMware Standard—vSwitch. The vSwitch has two port groups created: one labeled Management Networkfor management traffic and the other is labeled VM Network. The Management Network is a vmkernel port with the IP defined on the console attached to it.

In this example, our host contains six 10 Gigabit NICs that will connect the host to the network. You will define two additional vSwitches with two physical ports attached to each for redundancy. The additional vSwitches will handle storage and replication traffic on one and VM traffic on the other.

Note

Best practices of vSphere networking are far beyond the scope of this book. The network layout shown in the preceding diagram is not an endorsement of a particular layout and is for illustration purposes to show the PowerCLI cmdlets used to configure networking on ESXi.

How to do it...

To begin with, let's get an idea of the network layout that is in place, by default. From a default install, there is a single virtual switch named vSwitch0. The first cmdlet shows you the properties of this virtual switch and the second shows you the port groups associated with that vSwitch. To do this, review the output of the two PowerCLI cmdlets:
$esxihost | Get-VirtualSwitch$esxihost | Get-VirtualPortGroup –VirtualSwitch vSwitch0
The first thing to be completed is to remove the default VM Network port group, since it's not the best practice to have Virtual Machine traffic on the management ports, and this default port group is not a part of the design you outlined for this configuration:
$esxihost | Get-VirtualPortGroup -Name "VM Network" | Remove-VirtualPortGroup –Confirm:$false
The preceding command combines the Get-VirtualPortGroup and Remove-VirtualPortGroup cmdlets to change the confirmation. When executed, you will receive either a confirmation or an error. If the port group is connected to or in use by a VM, you will receive an error message. Once you remove the VM Network port group, the next step is to add an additional vmkernel port that will be used for vMotion.

Note

While this is outside the scope of this book, there are many different ideas for the best design of VMware networking. Most administrators agree that Management traffic and vMotion traffic should be separated, but with increasing speeds and capabilities of NICs today, it's common to see them sharing the same virtual switch. Administrators will set the Management traffic to be active on the first NIC and vMotion to be active on the second NIC. The two traffic streams will only be on the same NIC in a failover situation.

In our design, you will set Management and vMotion to be collocated on the same switch. To do this, use the New-VMHostNetworkAdapter cmdlet and pass in the name of the port group, the virtual switch, and the IP information. You will also pass in a parameter to specify that this vmkernel port should be used for VMotion as follows:
$esxihost | New-VMHostNetworkAdapter -PortGroup "VMotion Network" -VirtualSwitch vSwitch0 -IP 192.168.50.241 -SubnetMask 255.255.255.0 -VMotionEnabled $true
In our design, although vMotion and Management traffic exist on the same vSwitch, the traffic will be separated using active and standby links on each port group. This is done by changing the NIC Teaming Policy with the Set-NicTeamingPolicy cmdlet. You can see in the following two commands that the active and standby NIC assignments are opposite between the two port groups:
$esxihost | Get-VirtualPortGroup -Name "Management Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic0 –MakeNicStandby vmnic1$esxihost | Get-VirtualPortGroup -Name "VMotion Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic1 –MakeNicStandby vmnic0
The port group is automatically created and the vmkernel/host port is created for our vMotion network, but it's on the wrong VLAN. Our vMotion traffic is on a different VLAN, so you need to set this on the port group as follows:
$esxihost | Get-VirtualPortGroup -Name "VMotion Network" | Set-VirtualPortGroup –VlanID 50
The next step is to create a new virtual switch with its own uplinks on vmnic2 and vmnic3, as shown in our diagram. To confirm that the physical NICs exist, you can run the following cmdlet:
$esxihost | Get-VMHostNetworkAdapter

The Get-VMHostNetworkAdapter cmdlet displays all of the vmkernel ports along with all of the physical NICs present on the host.

After confirming the NIC, you will run the New-VirtualSwitch cmdlet to provision the new virtual switch. This cmdlet provisions the vSwitch with its uplinks, but it's currently an island with no connectivity for Management or virtual servers:
$esxihost | New-VirtualSwitch -Name vSwitch1 -Nic vmnic2,vmnic3
The next step is to create vmkernel ports for storage traffic and replication traffic. These are created in the same way as the VMotion Network we provisioned earlier:
$esxihost | New-VMHostNetworkAdapter -PortGroup "Storage Network" -VirtualSwitch vSwitch1 -IP 192.168.100.241 -SubnetMask 255.255.255.0 -VsanTrafficEnabled $true$esxihost | Get-VirtualPortGroup -Name "Storage Network" | Set-VirtualPortGroup –VlanID 100$esxihost | New-VMHostNetworkAdapter -PortGroup "FT Logging Network" -VirtualSwitch vSwitch1 -IP 192.168.200.241 -SubnetMask 255.255.255.0 -FaultToleranceLoggingEnabled $true$esxihost | Get-VirtualPortGroup -Name "FT Logging Network" | Set-VirtualPortGroup –VlanID 200
Again, you want to make sure that our Storage Traffic and Fault Tolerance traffic don't end up competing for bandwidth. Therefore, you will assign one port group to be active on one uplink and the other port group to be active on the second uplink. This is done again with the Set-NicTeamingPolicy cmdlet:
$esxihost | Get-VirtualPortGroup -Name "Storage Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic2 –MakeNicStandby vmnic3$esxihost | Get-VirtualPortGroup -Name "FT Logging Network" | Get-NicTeamingPolicy | Set-NicTeamingPolicy –MakeNicActive vmnic3 –MakeNicStandby vmnic2
The final step of our network provisioning is to create new port groups for Virtual Machine traffic. You have set all of the virtual machine traffic to its own vSwitch and uplinks in the design outlined. The first step is to create the virtual switch like you did for vSwitch1 as follows:
$esxihost | New-VirtualSwitch -Name vSwitch2 -Nic vmnic4,vmnic5
Once the virtual switch is created, you can create two port groups on the virtual switch. However, in this case, New-VirtualPortGroup doesn't allow any pipeline input, so you will need to specify the server as a parameter instead of passing it through the pipeline:
New-VirtualPortGroup -Name "Infrastructure Network" -VirtualSwitch vSwitch2 -VLanId 1 -Server 192.168.0.241New-VirtualPortGroup -Name "Application Network" -VirtualSwitch vSwitch2 -VLanId 2 -Server 192.168.0.241

How it works…

In this example, you will work with the VMHost