Book Image

PowerCLI Essentials

By : Chris Halverson
Book Image

PowerCLI Essentials

By: Chris Halverson

Overview of this book

Have you ever wished you could automatically get a report with all the relevant information about your VMware environments in exactly the format you want? Or that you could automate a crucial task that needs to be performed on a regular basis? Powerful Command Line Interface (PowerCLI) scripts do all these things and much more for VMware environments. PowerCLI is a command-line interface tool used to automate VMware vSphere environments. It is used to handle complicated administration tasks through use of various cmdlets and scripts, which are designed to handle certain aspects of VSphere servers and to help you manage them. This book will show you the intricacies of PowerCLI through real-life examples so that you can discover the art of PowerCLI scripting. At the start, you will be taught to download and install PowerCLI and will learn about the different versions of it. Moving further, you will be introduced to the GUI of PowerCLI and will find out how to develop single line scripts to duplicate running tasks, produce simple reports, and simplify administration. Next, you will learn about the methods available to get information remotely. Towards the end, you will be taught to set up orchestrator and build workflows in PowerShell with update manager and SRM scripts.
Table of Contents (13 chapters)
PowerCLI Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Building a VM script using all the pieces


Consider the following parameters:

  • Premise: Create a script that will prompt a user for information to build a new VM

  • Inputs: This includes vCPUs, memory, datacenter, DRS cluster, valid datastore, Resource Pool, VM folder, customization specification, and data disk size

  • Outputs: These are freshly built VM to specs

  • Assumptions: Data gathering will be done on valid information from the virtual environment itself; no hard coded information will be valid unless specified in the script to the user (for example, the OS disk size)

  • Script: Consider the following code snippet:

    Connect-vCenter.ps1
    <#
    .Synopsis
        Does the lifting of connecting to a vCenter
    .Description
        Starts VIMAutomation Module
        Gets Credentials
        Gets the vCenter name and connects to vCenter
    .Input
        User Input
            Credentials
            vCenter Name
    .Output
        None
    .Author
        Chris Halverson
    .Change Log
        11/6/2015
    .FileName
        Connect-vCenter.ps1
    .Version
        Draft...