Читать книгу VMware vSphere PowerCLI Reference - Graf Brian - Страница 7
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 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. Additionally, the book covers topics beyond vSphere administration, from how-tos for actually running your code to code version control.
Since the release of the first edition of this book, the VMware landscape has widened significantly and so with this release the scope of the areas covered has broadened too. With new chapters on vCloud Director, vCloud Air, vRealize Orchestrator and Site Recovery Manager, DevOps, and PowerActions, plus chapters on networking and storage enhanced with NSX and VSAN content, the range of places we can help you to automate has expanded significantly.
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. This book contains an extensive number of chapters for this phase.
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 module 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 module. So, even if you are primarily a *nix shop, you can still benefit 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 450+ PowerCLI cmdlets, but a practical guide with example functions and 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:
www.wiley.com/go/vmwarevspherepowercli2e
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 6.0
VMware vCenter Server, version 6.0
VMware ESXi, version 6.0
PowerShell, version 4.0 RTM and 5.0 preview
OS Platform, Windows 7 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 the PowerShell ISE, PowerGUI, and PowerShellPlus all give you a GUI-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
Chapters 1–5 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 Networking covers automation in one of the most critical components of a virtual environment: networking. We also take an introductory look at VMware NSX.
Chapter 4: Automating Storage features deploying a new cluster with new storage or maintaining and upgrading existing storage, automation can come to the rescue to help you save time and maintain consistency of configuration. We also look at VMware Virtual SAN.
Chapter 5: Using Advanced vSphere Features focuses on automating some of the most advanced features vSphere offers. EVC, vFlash Read Cache, DRS Groups, Fault Tolerance, and more: if you want to configure all the bells and whistles, this is the chapter!
Part II: Managing the Virtual Machine Life Cycle
Chapters 6–10 tackle all the automation aspects of guests – from creating a virtual machine 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 6: Creating Virtual Machines explores the various methods of creating new virtual machines, including how to scale up deployments while maintaining quality control. We will highlight several techniques for installing and maintaining VMware Tools.
Chapter 7: 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 8: 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 9: 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. Next, you explore how to script vMotion, Storage vMotion, and Cross-vCenter vMotion operations. Finally, we cover creating and maintaining snapshots.
Chapter 10: Using vApps shows you how to import virtual appliances, create your own vApps, maintain vApps, and simplify complex applications by providing vSphere valuable metadata about a group of VMs. You’ll learn about start order, network protocol profiles, using IP assignments, and modifying vApp product information.
Part III: Securing Your vSphere Environment
In Chapters 11–14, 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 11: 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 12: 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 backend database. Learn how to back up and restore your vCenter Server database when you don’t have SQL Server Management Studio available. This chapter will also walk you through both exporting and importing of specific objects found in your vCenter server, including roles and permissions, tags, folders, VM locations, and more.
Chapter 13: Hardening the vSphere Environment shows how you can use the Hardening Guides to secure your vSphere environment. After providing some familiarization with the Hardening Guide, this chapter provides methods for assessing and remediating the guidelines. You’ll find scripts that allow you to report the current settings, and some of the same scripts can also be used to configure these settings as advised in the Hardening Guide. The chapter also provides some tips on extending the functions described and explores PowerShell coding nuances.
Chapter 14: 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. ESXi 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
Chapters 15–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 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 15: Reporting and Auditing 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. The chapter also provides guidance on how to use PowerShell for data manipulation, including sorting, grouping, and formatting, as well as discussion of PowerShell objects and their properties/members.
Chapter 16: 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. This chapter also discusses sources of this data along with schedules for gathering metrics, how to adjust these schedules, and more!
Chapter 17: Alarms 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.
Part V: Integration
In Chapters 18–23, we expand to the wider VMware product world and examine how to integrate PowerCLI with the broader range of VMware product offerings.
Chapter 18: The SDK will show you how you can use the vSphere SDK. Now why would a book on PowerCLI bother with the vSphere SDK? The answer is simple. With the help of the vSphere SDK, your scripts can go that extra mile and perform functions that would otherwise not be available to you.
Chapter 19: vCloud Director examines how you can create and manage different aspects of your vCloud Director environment, from managing organizations to managing access control rules and vApps. This chapter will help you get a handle on automating mundane tasks that often plague vCloud Director administrators.
Chapter 20: vCloud Air builds off the previous chapter and walks you through connecting and automating vCloud Air using the new vCloud Air PowerCLI cmdlets. This chapter describes connecting to your target virtual datacenter as well as PowerCLI configuration that will allow you to quickly and easily connect to virtual machines in the cloud. Wrapping up the chapter, we show you how to work with the Cloud Infrastructure view (CIView) to invoke API methods that do not have associated PowerCLI cmdlets, allowing you to create your own advanced functions.
Chapter 21: vRealize Orchestrator examines VMware’s orchestration product and how to use PowerShell to integrate with systems when the native Orchestrator tools don’t suffice. We also look at how to manipulate the vRealize Orchestrator REST API with PowerShell.
Chapter 22: Site Recovery Manager walks you through reporting on the status of your protected virtual machines, adding and removing VMs from your recovery plans, and testing your disaster recovery plan using automation to trigger the test after each modification. Constant and consistent validation leads to confidence in your infrastructure when you need it.
Chapter 23: PowerActions examines VMware Flings and how to integrate your PowerCLI scripts into the vSphere Web Client.
Part VI: PowerCLI and DevOps
In Chapters 24 and 25, we expand on the automation scripts themselves. We’ll show you how to begin to work in a DevOps fashion by integrating with source control systems and methods for running your scripts.
Chapter 24: Source Control will show you how to safely store and track your code and also work on code projects as part of a team, using both in-house and publicly available source control tools.
Chapter 25: Running Scripts examines several ways to run a PowerShell script in your environment. We also provide hints and tricks on how to load modules, make logging a central part of your script, and even safely pass credentials into your scheduled task.
Appendix: Example Reports provides further discussion on the Reporting topic from Chapter 15. The stack of examples range from code snippets to blocks of code mining details and data to full-fledged functions for reporting on hardware devices and configurations, along with accompanying usage explanations.
NOTE You can download all the files and resources mentioned in the book from www.wiley.com/go/vmwarevspherepowercli2e.
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 or via Twitter as mentioned in the “About the Authors” section:
Matt Boren – The vNugglets at www.vNugglets.com
Luc Dekens – LucD Notes: My PowerShell Ramblings at www.lucd.info
Brian Graf – Brian Graf’s Virtualization Blog at www.vtagion.com
Jonathan Medd – Jonathan Medd’s Blog: Automating anything that moves.. at www.jonathanmedd.net
Glenn Sizemore – Practical Administrator: Lessons of a Datacenter Administrator at http://practical-admin.com, or @Glnsize on Twitter.
Andrew Sullivan – Practical Administrator: Lessons of a Datacenter Administrator at http://practical-admin.com
Wiley 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 Wiley website at www.wiley.com/go/vmwarevspherepowercli2e. 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.