You are previewing Learning PowerCLI.
O'Reilly logo
Learning PowerCLI

Book Description

Automate your Vmware vSphere environment by learning how to install and use PowerCLI. This book takes a practical tutorial approach that will have you automating your daily routine tasks in no time.

In Detail

VMware vSphere PowerCLI is a powerful command-line tool to automate all aspects of a VMware vSphere environment. PowerCLI 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.

"Learning PowerCLI" is a practical, hands-on guide that provides you with a thorough knowledge of VMware vSphere PowerCLI. This knowledge will help you to automate your routine tasks so you can save valuable time.

"Learning PowerCLI" introduces you to VMware vSphere PowerCLI, from downloading and installing the software to creating good-looking reports of your VMware vSphere environment.

You will learn about working with host profiles, configuring virtual switches, removing snapshots, configuring Storage DRS, working with affinity rules, configuring an alarm, and managing roles and permissions. You will learn everything you need to know to get started with automating your VMware vSphere infrastructure. All the examples in Learning PowerCLI can be used directly in your environment.

What You Will Learn

  • Download and install PowerCLI
  • Add hosts to VMware vCenter Server
  • Configure vSphere Auto Deploy
  • Use the esxcli command from PowerCLI
  • Create OS Customization Specs
  • Monitor virtual machine performance
  • Configure distributed virtual switches and storage I/O Control
  • Enable VM and Application Monitoring
  • Manage licenses for multiple hosts to migrate them easily
  • Configure an alarm to monitor your networks virtual machines
  • Generate a good-looking HTML report in no time
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning PowerCLI
      1. Table of Contents
      2. Learning PowerCLI
      3. Credits
      4. About the Author
      5. 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
      7. 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
      8. 1. Introduction to PowerCLI
        1. Downloading and installing PowerCLI
          1. Downloading PowerCLI
          2. Installing PowerCLI
        2. Modifying the PowerShell execution policy
        3. Connecting and disconnecting servers
          1. Connecting to a server
          2. Connecting to multiple servers
          3. Suppressing certificate warnings
          4. Disconnecting from a server
          5. Retrieving the PowerCLI configuration
        4. Using the credential store
        5. Retrieving a list of all of your virtual machines
          1. Suppressing displaying deprecated warnings
          2. Using wildcard characters
          3. Filtering objects
          4. Using comparison operators
          5. Using aliases
        6. Retrieving a list of all of your hosts
          1. Displaying the output in a grid view
        7. Summary
      9. 2. Learning Basic PowerCLI Concepts
        1. Using the Get-Command, Get-Help, and Get-Member cmdlets
          1. Using Get-Command
          2. Using Get-VICommand
          3. Using Get-Help
          4. Using Get-PowerCLIHelp
          5. Using Get-PowerCLICommunity
          6. Using Get-Member
        2. Using providers and PSDrives
          1. Using providers
          2. Using PSDrives
          3. Using the vSphere PowerCLI Inventory Provider
          4. Using the vSphere PowerCLI Datastore Provider
          5. Copying files between a datastore and your PC
        3. Using arrays and hash tables
        4. Creating calculated properties
        5. Using raw API objects with ExtensionData or Get-View
          1. Using the ExtensionData property
          2. Using the Get-View cmdlet
          3. Using Managed Object References
          4. Using the Get-VIObjectByVIView cmdlet
        6. Extending PowerCLI objects with the New-VIProperty cmdlet
        7. Working with vSphere folders
        8. Summary
      10. 3. Working with Objects in PowerShell
        1. Using objects, properties, and methods
          1. Using methods
        2. Expanding variables and subexpressions in strings
          1. Understanding what expands a string
          2. Expanding a string when it is used
        3. Using here-strings
        4. Using the pipeline
          1. Using the ByValue parameter binding
          2. Using the ByPropertyName parameter binding
        5. Using the PowerShell object cmdlets
          1. Using the Select-Object cmdlet
          2. Using the Where-Object cmdlet
          3. Using the ForEach-Object cmdlet
          4. Using the Sort-Object cmdlet
          5. Using the Measure-Object cmdlet
            1. Rounding a value
          6. Using the Group-Object cmdlet
          7. Using the Compare-Object cmdlet
          8. Using the Tee-Object cmdlet
        6. Creating your own objects
          1. Using the New-Object cmdlet
          2. Using a hash table to create an object
          3. Creating objects using the Select-Object cmdlet
          4. Adding properties to an object with Add-Member
          5. Using type declarations
        7. Using COM objects
        8. Summary
      11. 4. Managing vSphere Hosts with PowerCLI
        1. Adding a host to a VMware vCenter Server
          1. Creating a datacenter
          2. Creating a cluster
          3. Adding a host
        2. Enabling and disabling maintenance mode
        3. Working with host profiles
          1. Creating a host profile
          2. Attaching the host profile to a cluster or a host
          3. Testing the host profile for compliance
          4. Applying a host profile to a host or cluster
          5. Using host profile answer files
          6. Exporting a host profile
          7. Importing a host profile
        4. Working with host services
          1. Retrieving information about host services
          2. Starting a host service
          3. Stopping a host service
          4. Restarting a host service
          5. Modifying the startup policy of a host service
        5. Configuring the host firewall
          1. Getting the host firewall default policy
          2. Modifying the host firewall default policy
          3. Getting the host firewall exceptions
          4. Modifying a host firewall exception
        6. Configuring vSphere Image Builder and Auto Deploy
          1. Configuring Image Builder
          2. Configuring Auto Deploy
        7. Using esxcli from PowerCLI
          1. Listing all of the available esxcli commands
        8. Using the vSphere CLI commands from PowerCLI
        9. Removing a host from the VMware vCenter Server
        10. Summary
      12. 5. Managing Virtual Machines with PowerCLI
        1. Creating a virtual machine
          1. Creating a virtual machine from scratch
          2. Creating a virtual machine from a template
          3. Cloning a virtual machine
        2. Registering a virtual machine
        3. Using OS customization specifications
        4. Starting and stopping a virtual machine
          1. Starting a virtual machine
          2. Suspending a virtual machine
          3. Shutting down a virtual machine's guest operating system
          4. Stopping a virtual machine
        5. Modifying the settings of a virtual machine
          1. Using the VMware vSphere API
          2. Adding devices to a virtual machine
            1. Adding a hard disk
            2. Adding a SCSI controller
            3. Adding a network adapter
            4. Adding a floppy drive
            5. Adding a CD drive
          3. Modifying devices added to a virtual machine
            1. Modifying a hard disk
              1. Moving a hard disk to another datastore
            2. Modifying a SCSI controller
            3. Modifying a network adapter
            4. Modifying a floppy drive
            5. Modifying a CD drive
          4. Removing devices from a virtual machine
            1. Removing a hard disk
            2. Removing a network adapter
            3. Removing a floppy drive
            4. Removing a CD drive
        6. Converting a virtual machine into a template
          1. Converting a template into a virtual machine
          2. Modifying the name of a template
          3. Removing a template
        7. Moving a virtual machine to another folder, host, cluster, resource pool, or datastore
        8. Updating the VMware Tools
          1. Using the Update-Tools cmdlet
          2. Enabling the "Check and upgrade VMware Tools before each power on" checkbox
        9. Upgrading virtual machine compatibility
        10. Using snapshots
          1. Creating snapshots
          2. Retrieving snapshots
          3. Reverting to a snapshot
          4. Modifying snapshots
          5. Removing snapshots
        11. Running commands on the guest OS
        12. Configuring Fault Tolerance
          1. Turning Fault Tolerance on
          2. Turning Fault Tolerance off
        13. Opening the console of a virtual machine
        14. Removing a virtual machine
        15. Summary
      13. 6. Managing Virtual Networks with PowerCLI
        1. Using vSphere Standard Switches
          1. Creating vSphere Standard Switches
          2. Configuring vSphere Standard Switches
          3. Adding network adapters to a switch
          4. Removing vSphere Standard Switches
        2. Using host network adapters
          1. Creating host network adapters
          2. Retrieving host network adapters
          3. Configuring host network adapters
            1. Configuring network speed and the duplex setting
            2. Configuring the management network
            3. Configuring vMotion
          4. Removing host network adapters
          5. Configuring NIC Teaming
        3. Using standard port groups
          1. Creating standard port groups
          2. Configuring standard port groups
          3. Removing standard port groups
        4. Using vSphere Distributed Switches
          1. Creating vSphere Distributed Switches
            1. Creating a new vSphere Distributed Switch from scratch
            2. Cloning a vSphere Distributed Switch
            3. Creating a vSphere Distributed Switch from an export
          2. Retrieving vSphere Distributed Switches
          3. Configuring vSphere Distributed Switches
            1. Rolling back the configuration of a vSphere Distributed Switch
            2. Importing the configuration of a vSphere Distributed Switch from a backup
            3. Upgrading a vSphere Distributed Switch
          4. Adding hosts to vSphere Distributed Switches
          5. Adding host physical network adapters to a vSphere Distributed Switch
          6. Removing host physical network adapters from a vSphere Distributed Switch
          7. Removing hosts from a vSphere Distributed Switch
          8. Exporting the configuration of vSphere Distributed Switches
        5. Removing vSphere Distributed Switches
        6. Using distributed virtual port groups
          1. Creating distributed virtual port groups
            1. Creating distributed virtual port groups from a reference group
            2. Creating distributed virtual port groups from an export
          2. Configuring distributed virtual port groups
            1. Renaming a distributed virtual port group
            2. Rolling back the configuration of a distributed virtual port group
            3. Restoring the configuration of a distributed virtual port group
          3. Configuring Network I/O Control
            1. Enabling Network I/O Control
            2. Disabling Network I/O Control
          4. Exporting the configuration of distributed virtual port groups
          5. Migrating a host network adapter from a standard port group to a distributed port group
          6. Removing distributed virtual port groups
        7. Configuring host networking
        8. Configuring the network of a virtual machine
        9. Summary
      14. 7. Managing Storage with PowerCLI
        1. Rescanning for new storage devices
        2. Creating datastores
          1. Creating NFS datastores
          2. Getting SCSI LUNs
          3. Creating VMFS datastores
            1. Creating software iSCSI VMFS datastores
        3. Retrieving datastores
        4. Setting the multipathing policy
        5. Configuring the vmhba paths to a SCSI device
          1. Retrieving the vmhba paths to a SCSI device
          2. Modifying the vmhba paths to a SCSI device
        6. Working with Raw Device Mappings
        7. Configuring Storage I/O Control
          1. Retrieving Storage I/O Control settings
        8. Configuring Storage DRS
          1. Creating a Datastore Cluster
          2. Retrieving Datastore Clusters
          3. Modifying Datastore Clusters
          4. Adding datastores to a Datastore Cluster
          5. Retrieving the datastores in a Datastore Cluster
          6. Removing datastores from a Datastore Cluster
          7. Removing Datastore Clusters
        9. Upgrading datastores to VMFS-5
        10. Removing datastores
        11. Summary
      15. 8. Managing High Availability and Clustering with PowerCLI
        1. Creating vSphere HA and DRS clusters
        2. Retrieving clusters
          1. Retrieving the HA master or primary hosts
          2. Retrieving cluster configuration issues
        3. Modifying cluster settings
          1. Disabling HA
          2. Disabling or enabling host monitoring
          3. Associating a host profile with a cluster
          4. Enabling VM and application monitoring
          5. Configuring the heartbeat datastore selection policy
        4. Moving hosts to clusters
        5. Moving clusters
        6. Using DRS rules
          1. Creating VM-VM DRS rules
          2. Creating VM-Host DRS rules
            1. Creating virtual machines DRS groups
            2. Creating hosts DRS groups
            3. Retrieving DRS groups
            4. Modifying DRS groups
              1. Adding virtual machines to a DRS group
              2. Removing virtual machines from a DRS group
            5. Removing DRS groups
            6. Creating virtual machines to hosts DRS rules
          3. Retrieving DRS rules
          4. Modifying DRS rules
          5. Removing DRS rules
        7. Using DRS recommendations
        8. Using resource pools
          1. Creating resource pools
          2. Retrieving resource pools
          3. Modifying resource pools
          4. Moving resource pools
          5. Configuring resource allocation between virtual machines
          6. Removing resource pools
        9. Using Distributed Power Management (DPM)
          1. Enabling DPM
          2. Configuring hosts for DPM
          3. Testing hosts for DPM
            1. Putting hosts in standby mode
            2. Starting hosts
          4. Retrieving the DPM configuration of a cluster
          5. Disabling DPM
        10. Removing clusters
        11. Summary
      16. 9. Managing vCenter with PowerCLI
        1. Working with roles and permissions
          1. Retrieving privileges
          2. Using roles
            1. Creating roles
            2. Retrieving roles
            3. Modifying roles
            4. Removing roles
          3. Using permissions
            1. Creating permissions
            2. Retrieving permissions
            3. Modifying permissions
            4. Removing permissions
        2. Managing licenses
          1. Adding license keys to the license inventory
          2. Retrieving license keys from the license inventory
          3. Removing license keys from the license inventory
          4. Assigning licenses to hosts
          5. Retrieving assigned licenses
          6. Removing assigned license keys from hosts
          7. Using the LicenseDataManager
            1. Associating license keys with host containers
            2. Applying the associated license key to all the hosts in the container
            3. Retrieving license key associations
              1. Retrieving all of the license key associations to the host containers in your environment
              2. Retrieving the license keys associated with a specific host container
              3. Retrieving the effective license key of a host container
            4. Modifying license key associations
            5. Removing license key associations
        3. Configuring alarms
          1. Retrieving alarm definitions
          2. Modifying alarm definitions
          3. Creating alarm actions
            1. Configuring the vCenter Server mail server and sender settings
          4. Retrieving alarm actions
          5. Removing alarm actions
          6. Creating alarm action triggers
          7. Retrieving alarm action triggers
          8. Removing alarm action triggers
        4. Retrieving events
        5. Summary
      17. 10. Reporting with PowerCLI
        1. Retrieving log files
        2. Creating log bundles
        3. Performance reporting
          1. Retrieving the statistical intervals
          2. Retrieving performance statistics
          3. Retrieving metric IDs
        4. Exporting reports to CSV files
        5. Generating HTML reports
        6. Sending reports by e-mail
        7. Reporting the health of your vSphere environment with vCheck
        8. Using PowerGUI
        9. Summary
      18. Index