Mastering PowerCLI

Book description

Master PowerCLI to automate all aspects of VMware environments

About This Book

  • Leverage PowerCLI to perform administration tasks in a more effective and efficient way
  • Escape from daily tedious and repetitive tasks by unleashing the full potential of your creative side through scripting
  • Master the intricate workings of PowerShell and PowerCLI through easy and real-life examples

Who This Book Is For

If you are a system administrator with working knowledge of PowerShell and PowerCLI who wants to perform quick and easy scripting but at the same time achieve complex results and write production grade scripts, then this book is for you.

What You Will Learn

  • Use GitHub for collaboration and Pester to automate unit tests
  • Write advanced reusable functions and dynamic variables and learn about error handling in PowerShell
  • Automate ESXi host installation using Auto-Deploy, host profile, and host image
  • Implement security best practices in a vSphere data center
  • Manage SRM, vCloud Air, and vRealize Operations environments
  • Access and utilize vSphere APIs to manage advanced aspects of vSphere and work with .NET view objects
  • Utilize REST APIs to manage vRealize Automation environments
  • Create a Windows GUI through the use of PowerShell and Sapien PrimalForms CE

In Detail

Have you ever wished that every morning you could automatically get a report with all the relevant information about your datacenter in exactly the same format you want? Or whether you could automate that boring, exhausting task? What if some crucial task needs to be performed on a regular basis without any error? PowerCLI scripts do all that and much more for VMware environments. It is built on top of the popular Windows PowerShell, with which you can automate server tasks and reduce manual input, allowing you to focus on more important tasks.

This book will help you to achieve your goals by starting with a short refresher on PowerShell and PowerCLI and then covering the nuances of advanced functions and reusable scripts. Next you will learn how to build a vSphere-powered virtualized datacenter using PowerCLI while managing different aspects of the environment including automated installation, network, and storage. You will then manage different logical constructs of vSphere environment and different aspects of a virtual machine.

Later, you will implement the best practices for a security implementation in vSphere Environment through PowerCLI before discovering how to manage other VMware environments such as SRM, vCloud Director and vCloud Air through PowerCLI. You will also learn to manage vSphere environments using advanced properties by accessing vSphere API and REST APIs through PowerCLI.

Finally, you will build a Windows GUI application using PowerShell followed by a couple of sample scripts for reporting and managing vSphere environments with detailed explanations of the scripts. By the end of the book, you will have the required in-depth knowledge to master the art of PowerCLI scripting.

Style and approach

In this book, every topic is explained in a very easy-to-follow fashion with real-life, simple examples so that you get an idea of not only the topic but also the context in which it should be used or where it can be best utilized.

Table of contents

  1. Mastering PowerCLI
    1. Table of Contents
    2. Mastering PowerCLI
    3. Credits
    4. Foreword
    5. About the Author
    6. Acknowledgment
    7. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
        3. Instant updates on new Packt books
    9. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    10. 1. PowerShell and PowerCLI Refresher
      1. The essence of PowerShell and PowerCLI
        1. The history of scripting
        2. PowerShell
        3. PowerCLI
        4. The vSphere PowerCLI package
        5. The vCloud PowerCLI package
      2. Implementing programming constructs in PowerShell
        1. Conditional logic
          1. Conditional logic using loops
            1. The difference between Foreach and Foreach-object
      3. Automation through PowerShell scripts
      4. Running and scheduling scripts
      5. Using version control with GitHub
        1. The fork & pull model
        2. The shared repository model
        3. Branch
      6. Testing your scripts using Pester
      7. Connecting to a vCenter and other VMware environments using PowerCLI cmdlets
      8. Summary
    11. 2. Reusable Advanced Functions and Scripts
      1. Specifying function attributes
      2. Specifying parameter attributes
      3. Using parameter validation attributes
      4. Dynamic parameters
      5. Switch parameters
      6. PowerShell help files
      7. Creating comment-based help
      8. Error handling in PowerShell
      9. Summary
    12. 3. Deploying vSphere Hosts
      1. Image Builder with PowerCLI
      2. Using host profiles
      3. Configuring Auto Deploy for ESXi hosts
      4. Adding hosts to a vCenter server
      5. Summary
    13. 4. Managing Networks
      1. Managing vSphere standard switches
      2. Managing networking for ESXi
      3. Managing vSphere distributed switches
      4. Managing port groups
      5. Creating private VLANs
      6. Configuring vSphere network I/O control
      7. Configuring Netflow
      8. Working with ports
        1. Configuring traffic shaping
        2. Configuring port blocking
        3. Configuring the security policy
        4. Configuring the teaming policy
      9. Summary
    14. 5. Managing Storage
      1. Managing datastores
      2. Configuring Fibre Channel storage
      3. Configuring iSCSI storage
      4. Configuring NFS storage
      5. Configuring virtual SAN
      6. Using datastore clusters
      7. Using Raw Device Mapping
      8. Managing storage using storage policy-based management
        1. Cmdlets related to policy rules
        2. Cmdlets related to storage policy
        3. Cmdlets related to Spbm capabilities and compatible storage
        4. Cmdlets related to policy application
        5. Cmdlets related to policy backup and migration
      9. Applying VMFS resignaturing
      10. Configuring vFLASH using PowerCLI Extensions
      11. Summary
    15. 6. Managing Clusters and Other Constructs
      1. Configuring vCenter logical constructs
        1. Folder
        2. Datacenter
        3. Cluster
      2. Configuring the Enhanced vMotion Compatibility mode
      3. Configuring High Availability
      4. Using Dynamic Resource Scheduling
      5. Using the DRS affinity and anti-affinity rules
      6. Managing resource pools
      7. Managing alarms
      8. Summary
    16. 7. Managing Virtual Machines
      1. Creating virtual machines
      2. Modifying virtual machines
        1. Hard disks
        2. Network adapters and USB devices
        3. Passthrough devices
        4. Snapshots
        5. Resource configuration and policies
        6. Managing VMware tools in a VM
      3. Managing templates
      4. Managing OS customization specifications
      5. Managing the guest OS
      6. Managing vApps
      7. Summary
    17. 8. Managing vSphere Security, SRM, vCloud Air, and vROps
      1. The vSphere Security Hardening Guide
      2. Managing vSphere Update Manager
      3. Configuring a firewall and services in an ESXi host
      4. Managing host profiles
      5. Managing vCenter Site Recovery Manager
      6. Managing vCloud Air
      7. Managing vRealize Operations Manager
      8. Summary
    18. 9. Managing the vSphere API
      1. Using the Get-View cmdlet to return .NET View objects
      2. Using the ExtensionData property to return .NET View objects
      3. Using the vSphere API
      4. Creating a vSphere scheduled task
      5. Configuring Distributed Power Management
      6. Configuring Fault Tolerance
      7. Managing Content Libraries
      8. Managing SRM advanced configurations
      9. Generating PowerCLI code using Onyx
      10. PowerActions for vSphere Web Client
      11. Summary
    19. 10. Using REST APIs
      1. Introducing REST APIs
      2. Introducing JSON
        1. Syntax rules
        2. Values
      3. The Invoke-RestMethod cmdlet
      4. vRealize Automation REST APIs
      5. Authenticating and getting a vRA token
      6. Managing tenants
        1. Creating a tenant
        2. Listing identity stores for a tenant
        3. Linking an identity store to a tenant
      7. Managing machines
        1. Listing shared and private catalog items
      8. Managing approvals
      9. Managing provisioned resources
      10. Managing network profiles
      11. Summary
    20. 11. Creating Windows GUI
      1. Different ways to create a Windows GUI
      2. Building a GUI using Windows Forms
        1. Creating a button
        2. Creating a TextBox
        3. Creating ListBox
        4. Creating CheckBox
      3. Using SAPIEN PowerShell Studio
      4. Building GUI using WPF
      5. Summary
    21. 12. Best Practices and Sample Scripts
      1. Best practices
      2. Security Hardening Script
      3. Capacity check report
        1. Parameter descriptions
      4. Using a proper editor
        1. Sublime Text
        2. ISESteroids
      5. Summary
    22. Index

Product information

  • Title: Mastering PowerCLI
  • Author(s): Sajal Debnath
  • Release date: October 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785286858