38,99 €
Master vSphere automation with this comprehensive reference VMware vSphere PowerCLI Reference, Automating vSphere Administration, 2nd Edition is a one-stop solution for vSphere automation. Fully updated to align with the latest vSphere and PowerCLI release, this detailed guide shows you how to get the most out of PowerCLI's handy cmdlets using real-world examples and a practical, task-based approach. You'll learn how to store, access, update, back up, and secure massive amounts of data quickly through the power of virtualization automation, and you'll get acquainted with PowerCLI as you learn how to automate management, monitoring, and life-cycle operations for vSphere. Coverage includes areas like the PowerCLI SDK, SRM, vCOPS, and vCloud Air. Plus guidance toward scheduling and viewing automation, using DevOps methodology and structured testing and source control of your PowerCLI scripts. Clear language and detailed explanations make this reference the manual you've been looking for. This book is your complete reference for managing vSphere in a Windows environment, with expert instruction and real-world application. * Automate vCenter Server deployment and configuration * Create and configure virtual machines, and utilize vApps * Monitor, audit, and report the status of your vSphere environment * Secure, back up, and restore your virtual machines * Work with other vSphere components from your PowerCLI scripts * Take control of your PowerCLI scripts through versioning and structured testing Don't spend another day slogging through routine systems management -- automate it, with this invaluable guide.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 837
Veröffentlichungsjahr: 2015
Titlepage
Copyright
Dedication
Acknowledgments
About the Authors
Introduction
Part I: Install, Configure, and Manage the vSphere Environment
Chapter 1: Automating vCenter Server Deployment and Configuration
Prepare the vCenter Installation
Create an Automated Installation
Set Up Your vCenter Server Folder Structure
Define Users and Their Privileges
Configure Datacenters and Clusters
Licensing
Chapter 2: Automating vSphere Hypervisor Deployment and Configuration
Prepare for an Installation
Automate an Installation
Chapter 3: Automating Networking
Chapter 4: Automating Storage
Set Up the Storage
Storage Policies
vSphere APIs for I/O Filtering
VSAN
Part II: Managing the Virtual Machine Life Cycle
Using Advanced vSphere Features
Configure EVC
vFlash Read Cache
Manage DRS Groups
Use Fault Tolerance
Use Distributed Power Management
Configure Host Profiles
Configure Active Directory Integration
Chapter 6: Creating Virtual Machines
Use the New-VM Cmdlet
Perform a Mass Deployment
Maintain VMware Tools
Chapter 7: Using Templates and Customization Specifications
Use Customization Specifications
Use Templates
Chapter 8: Configuring Virtual Machine Hardware
Add, Configure, and Remove Virtual Hardware
Optimize Storage Usage with Thin Provisioning
Chapter 9: Advanced Virtual Machine Features
Interact with the Guest OS
Use vMotion and Storage vMotion
Use and Manage Snapshots
Chapter 10: Using vApps
Import Virtual Appliances
Create Your Own vApps
Maintain vApps
Part III: Securing Your vSphere Environment
Chapter 11: Backing Up and Restoring Your Virtual Machines
Work with Snapshots
Create Do-It-Yourself Backups
Restore Your VMs from a DIY Backup
Change Block Tracking
Provide PowerShell Support for Corporate Backup Applications
Chapter 12: Organize Your Disaster Recovery
Back Up Your vCenter Server Database
Restore Your vCenter Server
Export vCenter Server Inventory Items
Import vCenter Server Inventory Items
Recover Virtual Machines
Chapter 13: Hardening the vSphere Environment
Use the Hardening Guides
Work with the Guidelines
Bring It All Together
Chapter 14: Maintain Security in Your vSphere Environment
Install the vCenter Update Manager PowerCLI Snap-in
Work with Baselines
Work with Upgrades and Patches
Report the Security Status
Applying Patches Without vSphere Update Manager
Part IV: Monitoring and Reporting
Chapter 15: Reporting and Auditing
The Basics
Information Sources
Report Formats
Chapter 16: Using Statistical Data
Understand Some Basic Concepts
Gather Statistical Data
Offload Statistical Data
Chapter 17: Alarms
Determine What to Monitor
Use Alarms
Part V: Integration
Chapter 18: The SDK
Work with the vSphere SDK
Use the vSphere API Reference
Use Managed Objects
Code Parameter Objects
Find the Method You Need
Understand Return Values and Faults
Put Some Tips and Tricks to Good Use
Chapter 19: vCloud Director
Prerequisites
Connecting to vCloud Director
Manage Organizations
Manage Users
Manage vDCs
Manage vApps
Manage VMs
vCloud Director Networks
Search-Cloud
Chapter 20: vCloud Air
Prerequisites
General
vCloud Air Authentication
Set-PowerCLIConfiguration
Open-VMConsoleWindow
Tasks
Get-CIView
Chapter 21: vRealize Orchestrator
Requirements
Running an External Script
Receiving a Return Code from an External Script
Use Cases
Alternative Method to the PowerShell Plug-in
Calling vRO Workflows from PowerShell
Chapter 22: Site Recovery Manager
What Is SRM?
Exploring the SRM Cmdlets
Chapter 23: PowerActions
Requirements
Installation and Initial Configuration
PowerCLI Console
PowerCLI Scripts
Further Use Cases
Final Thoughts
Part VI: PowerCLI and DevOps
Chapter 24: Source Control
File Services
Apache Subversion
GitHub
Chapter 25: Running Scripts
What Is a Script?
Executing a Script
Script Tips and Hints
Getting Help
Appendix: Example Reports
Virtual Machines
Guest Operating Systems
Hosts
Clusters
End-User License Agreement
Table 6-1
Table 8-1
Table 8-2
Table 8-3
Table 9-1
Table 9-2
Table 13-1
Table 14-1
Table 14-2
Table 16-1
Table 16-2
Table 17-1
Table 17-2
Table 17-3
Table 17-4
Table 17-5
Table 17-6
Table 18-1
Table 18-2
Table 18-3
Table 18-4
Table 19-1
Figure 1-1
Figure 1-2
Figure 1-3
Figure 1-4
Figure 1-5
Figure 2-1
Figure 2-2
Figure 2-3
Figure 2-4
Figure 3-1
Figure 4-1
Figure 4-2
Figure 4-3
Figure 6-1
Figure 6-2
Figure 8-1
Figure 8-2
Figure 9-1
Figure 12-1
Figure 12-2
Figure 12-3
Figure 14-1
Figure 14-2
Figure 14-3
Figure 14-4
Figure 14-5
Figure 15-1
Figure 15-2
Figure 15-3
Figure 15-4
Figure 16-1
Figure 16-2
Figure 16-3
Figure 16-4
Figure 17-1
Figure 17-2
Figure 18-1
Figure 18-2
Figure 18-3
Figure 18-4
Figure 18-5
Figure 18-6
Figure 18-7
Figure 18-8
Figure 18-9
Figure 18-10
Figure 18-11
Figure 18-12
Figure 18-13
Figure 18-14
Figure 18-15
Figure 18-16
Figure 19-1
Figure 19-2
Figure 21-1
Figure 21-2
Figure 21-3
Figure 21-4
Figure 21-5
Figure 21-6
Figure 21-7
Figure 21-8
Figure 21-9
Figure 21-10
Figure 21-11
Figure 21-12
Figure 21-13
Figure 21-14
Figure 21-15
Figure 21-16
Figure 21-17
Figure 21-18
Figure 21-19
Figure 21-20
Figure 21-21
Figure 21-22
Figure 21-23
Figure 21-24
Figure 21-25
Figure 21-26
Figure 21-27
Figure 21-28
Figure 21-29
Figure 21-30
Figure 21-31
Figure 21-32
Figure 21-33
Figure 21-34
Figure 21-35
Figure 21-36
Figure 21-37
Figure 21-38
Figure 21-39
Figure 21-40
Figure 21-41
Figure 21-42
Figure 23-1
Figure 23-2
Figure 23-3
Figure 23-4
Figure 23-5
Figure 23-6
Figure 23-7
Figure 23-8
Figure 23-9
Figure 23-10
Figure 23-11
Figure 23-12
Figure 23-13
Figure 23-14
Figure 23-15
Figure 23-16
Figure 23-17
Figure 23-18
Figure 23-19
Figure 23-20
Figure 23-21
Figure 23-22
Figure 23-23
Figure 23-24
Figure 23-25
Figure 23-26
Figure 23-27
Figure 23-28
Figure 23-29
Figure 23-30
Figure 23-31
Figure 23-32
Figure 23-33
Figure 23-34
Figure 23-35
Figure 23-36
Figure 24-1
Figure 24-2
Figure 24-3
Figure 24-4
Figure 24-5
Figure 24-6
Figure 24-7
Figure 24-8
Figure 24-9
Figure 24-10
Figure 24-11
Figure 24-12
Figure 24-13
Figure 24-14
Figure 24-15
Figure 24-16
Figure 24-17
Figure 24-18
Figure 24-19
Figure 24-20
Figure 24-21
Figure 24-22
Figure 24-23
Figure 24-24
Figure 24-25
Figure 24-26
Figure 24-27
Figure 24-28
Figure 24-29
Figure 24-30
Figure 24-31
Figure 24-32
Figure 24-33
Figure 24-34
Figure 24-35
Figure 24-36
Figure 24-37
Figure 24-38
Figure 24-39
Figure 24-40
Figure 24-41
Figure 24-42
Figure 24-43
Figure 24-44
Figure 24-45
Figure 24-46
Figure 24-47
Figure 24-48
Figure 24-49
Figure 24-50
Figure 24-51
Figure 24-52
Figure 24-53
Figure 24-54
Figure 24-55
Figure 24-56
Figure 24-57
Figure 24-58
Figure 24-59
Figure 24-60
Figure 25-1
Figure 25-2
Figure 25-3
Figure 25-4
Figure 25-5
Figure 25-6
Cover
Title Page
Front Matter
Dedication
Introduction
Chapter 1: Automating vCenter Server Deployment and Configuration
Start Reading
Example Reports
End-User License Agreement
iii
iv
v
vii
viii
ix
x
xxiii
xxiv
xxv
xxvi
xxvii
xxviii
xxix
xxx
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
26
27
28
29
30
31
32
33
34
35
36
37
38
39
41
42
43
44
45
46
47
48
49
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
1
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
230
231
232
233
234
235
236
237
238
239
240
241
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
426
427
428
429
430
431
432
433
434
435
436
437
438
439
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
486
487
488
489
490
491
492
493
494
497
498
499
500
501
502
503
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
542
543
544
545
546
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
621
622
623
624
625
626
628
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
679
680
681
682
683
684
685
686
687
688
689
690
691
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
719
720
721
722
724
725
726
727
728
729
730
731
732
735
738
739
740
741
742
743
744
746
748
749
750
751
753
755
756
757
758
759
760
761
764
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
811
812
813
815
816
817
826
827
829
832
833
836
838
841
842
843
844
850
851
852
853
855
856
860
861
862
865
866
867
870
871
872
873
874
875
876
877
878
879
881
883
885
887
888
891
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
211
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
Second Edition
Luc Dekens
Jonathan Medd
Brian Graf
Glenn Sizemore
Andrew Sullivan
Matt Boren
Copyright © 2016 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-92511-9
ISBN: 978-1-118-82513-3 (ebk.)
ISBN: 978-1-118-92514-0 (ebk.)
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2015958016
TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. VMware vSphere and PowerCLI are trademarks or registered trademarks of VMware, Inc. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
10 9 8 7 6 5 4 3 2 1
Senior Acquisitions Editor: Stephanie McComb
Development Editor: ME Schutz
Technical Editor: Matt Boren
Production Editor: Christine O’Connor
Copy Editor: Elizabeth Welch
Editorial Manager: Mary Beth Wakefield
Production Manager: Kathleen Wisor
Associate Publisher: Jim Minatel
Book Design and Composition: Maureen Forys, Happenstance Type-O-Rama
Proofreader: Amy Schneider
Indexer: Nancy Guenther
Project Coordinator, Cover: Brent Savage
Cover Designer: Wiley
Cover Image: Getty Images/Thomas Northcut
To Mom and Dad: I can do this because of you—thank you! —Matt
To my family, friends, and colleagues: This took quite a bit of our time away. —Luc
For Ellen, my wife, my inspiration, and my best friend —Brian
To my family, thanks for waiting for me to complete this during all those evenings when there were far more interesting things for us to do. I’m back now —Jonathan
To my family, for letting me do another one of these —Glenn
To my children, you motivate me to be the person you believe I am —Andrew
Thanks to the other authors on this book for making this book, and for being open to (most of) the feedback from the technical editor (feedback given in efforts to make functionality and features even better). And thank you, Gentle Editor, development editor Mary Ellen Schutz, for the guidance and wrangling throughout. LucD, thank you for what you do for the community, and for bringing me in on this project. Thank you, Jeffrey Snover, for risking life, limb, and career to make the great changes at Microsoft that then brought PowerShell, and a new attitude, to the world. Thanks also to the Microsofties responsible for PowerShell, and to those from VMware who have made PowerCLI a great product. And, to my wife, thank you much for tolerating the hours and days of me, locked in the office, poring over the manuscript and code—IHLY.
—Matt
Thanks to my fellow authors and all the people at Sybex who were involved with this book. And a special thanks to “our Gentle Editor, the little old lady from Wisconsin,” development editor Mary Ellen Schutz. She had to organize all this geek talk into the book you’re now holding in your hands. I would also like to thank all the people from VMware who produced such a great product, especially the PowerCLI Development Team in Sofia, Bulgaria, and Carter Shanklin, who made this product what it is today. Thanks also to Pablo Roesch; although we aren’t developers, we appreciate the drive with which you help us evangelize this wonderful piece of software. And finally, thanks to Jeffrey Snover and the PowerShell Team at Microsoft. Without PowerShell, none of this would have been possible. You shook the automation world!
—Luc
I’d like to thank my wife, Ellen, the love of my life, for patiently supporting me in my ambitions and endeavors, and my children, who bring me such happiness and joy. I would like to thank my parents for their kindness and love and for enabling me to reach my potential.
I’d like to thank Chad Hancock for igniting my desire to learn and grow because of his passion for teaching and empowering his students. I’d also like to thank the other authors for believing in me and allowing me this opportunity to write with them.
—Brian
Thanks to the other authors for their contributions, especially for helping answer some of my queries. Particular thanks to our development editor Mary Ellen Schutz for taking us on again, despite the experience she had with us the first time around (!), and steering us on the path to getting the book complete. Thanks to Matt Boren for really keeping me on my toes with the quality of my code. Also to John Williams for producing so many great soundtracks that helped me concentrate during the late nights getting this stuff done.
—Jonathan
I’d like to thank my wife, Kristine, and children, Zachary and Emma, for being awesome. This was a tough one, but with your understanding and support we did it, again. I would also like to thank Luc for getting the band back together for one last ride. It was an honor and privilege to be invited back into this cabal of automation ninjas. Finally, I would thank all the thousands of professionals with whom I continue to interact. Together we are really making a difference, and moving the needle. Keep it up, gang, and be nice to each other in the process.
—Glenn
Nothing would be possible without my wife, Leslie, without whom I couldn’t make it through the day. Your support, tolerance, and love make me a better person; thank you. To Glenn, your enthusiasm, optimism, and all-around brilliance are an inspiration. Don’t ever change. And finally, to my co-authors, thank you all. The teamwork and help throughout this project has humbled me on many occasions.
—Andrew
Of course the book wouldn’t be possible at all without the Sybex team: Mary Beth Wakefield, content development manager; Stephanie McComb, acquisitions editor; Mary Ellen Schutz, development editor; Matt Boren, technical editor; Christine O’Connor, production editor; Elizabeth Welch, copyeditor; Amy J. Schneider, proofreader; and Nancy Guenther, indexer.
In particular, we would like to thank our development editor, Mary Ellen Schutz, for making us all literate. Without her attention to detail, we wouldn’t have been able to produce the complete manual you’re now reading. Arnim van Lieshout, your writing was missed this time, but your work from the first edition permeates its way throughout this edition. Alan Renouf, we missed you this time from the writing piece, but you were an outstanding help in your new role at VMware in getting us access to betas and answers to questions. Finally, we would like to thank Matt Boren, our technical editor. Matt held us all to the highest standards. He left no script unturned and no explanation unchecked. He served as the gatekeeper, ensuring that any code you find herein will run the first time, every time. While we didn’t always see eye to eye, without the professionals at Sybex this book would never have been possible. Thanks, guys, it was a blast.
Matt Boren likes quick, efficient things. Automation? Great. Elegant automation with PowerShell? Even better, he says. Matt began his automation career with Perl and the like in the late 1990s. After many languages across several years, he came to enjoy PowerShell with v1.0 and the VMware VI Toolkit. A couple of years later, in 2009, Matt and his friend AC started the http://vNugglets.com blog, which is now a hearty store of mainly virtualization-focused PowerShell automation nugglets, where the posts also focus on keeping things fast as fast can be. After a few more years, Matt earned the VMware vExpert designation thanks to these blogging efforts and to his VMware Technology Network (VMTN) PowerCLI forum participation. He has held vExpert status four years so far, each year from 2012 to present (2015). Matt continues to find joy in making things faster, stronger, and better. Follow Matt on Twitter at (@mtboren).
Luc Dekens started many moons ago in the mainframe world as a system programmer. While the companies he worked for took Unix and Windows boxes on board, it was a natural evolution for him to expand into those areas. A couple of years ago, Luc was impressed by a new scripting tool, Monad, that Microsoft was bringing to market. When the organization Luc works for was expanding their virtualization platform, he stumbled on a product called VI Toolkit. It was ideal for automating many administrative tasks. Luc was admitted to the early beta program and started contributing to the ever-growing PowerCLI community. After attending VMworld 2009 in San Francisco, where he did a session together with Hal Rottenberg, Luc started a blog (http://lucd.info).
Brian Graf has worked in many different roles in IT for more than 10 years. He has always had a passion for technology and learning. For the past four years, Brian has focused mainly on virtualization and automation. Brian is a multi-year vExpert and is currently VCAP5-DCA and DCD certified. Brian graduated with a Masters of Information Systems from the University of Utah. He enjoys taking trips and spending time with his wife and kids. You can follow Brian on Twitter at https://twitter.com/vBrianGraf or on his blog at http://www.vtagion.com.
Jonathan Medd is a Senior Consultant with Xtravirt in the UK. He shares PowerShell and other automation content via his blog, http://jonathanmedd.net, and also co-hosts the Get-Scripting PowerShell podcast, which provides information on how to learn PowerShell and what’s going on in the PowerShell world—you can find it at http://get-scripting.blogspot.com. In April 2010, Jonathan was awarded status as a Microsoft Most Valuable Professional (MVP) for PowerShell and in 2011 gained the status of VMware vExpert. He has been re-awarded with each of those community awards in every year since. You can follow him on Twitter at http://twitter.com/jonathanmedd.
Glenn Sizemore has held just about every position one could hold in Enterprise IT—everything from cable dog to enterprise architect. Throughout it all, automation has been a passion. He started scripting early in his IT career and had mastered VBScript by the time PowerShell first shipped. He was an early adopter and supporter of PowerShell, and the desire to automate all the things propelled him higher into the solution stack. Today Glenn is a FlexPod Reference Architect at NetApp, where he builds cloud integrated turnkey architectures for use by customers of all sizes. Outside of work, Glenn is the proud father of two beautiful children, an avid automation evangelist, and a hater of negativity.
Andrew Sullivan has worked in the information technology industry for nearly 15 years, with a rich history of database development and administration, DevOps experience, virtualization and storage architecture, and automation evangelism. Andrew started as a Linux administrator fluent in Perl and Python many years ago, but has since learned the error of his ways and now favors PowerShell whenever possible. He blogs infrequently at http://practical-admin.com, pontificating about PowerShell for virtualization and storage automation, vRealize integration for storage systems, and occasionally some actual wisdom. Andrew is the co-host of the NetApp Tech ONTAP podcast, focusing on the NetApp storage ecosystem, and is a regular presenter at VMUGs, Docker Meetups, and other community events.
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!”
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.
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.
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.
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.
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 [email protected]. 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.
Chapter 1: Automating vCenter Server Deployment and Configuration
Chapter 2: Automating vSphere Hypervisor Deployment and Configuration
Chapter 3: Automating Networking
Chapter 4: Automating Storage
Chapter 5: Using Advanced vSphere Features
