Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PowerCLI Cookbook

You're reading from   PowerCLI Cookbook Over 75 step-by-step recipes to put PowerCLI into action for efficient administration of your virtual environment

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784393724
Length 274 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Philip Brandon Sellers Philip Brandon Sellers
Author Profile Icon Philip Brandon Sellers
Philip Brandon Sellers
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Configuring the Basic Settings of an ESXi Host with PowerCLI 2. Configuring vCenter and Computing Clusters FREE CHAPTER 3. Managing Virtual Machines 4. Working with Datastores and Datastore Clusters 5. Creating and Managing Snapshots 6. Managing Resource Pools, Reservations, and Limits for Virtual Machines 7. Creating Custom Reports and Notifications for vSphere 8. Performing ESXCLI and in-guest Commands from PowerCLI 9. Managing DRS and Affinity Groups using PowerCLI 10. Working with vCloud Director from PowerCLI A. Setting up and Configuring vCloud Director Index

Connecting to an ESXi host or a vCenter instance

To begin working with PowerCLI, you must first have PowerShell installed and available on the system on which you will run PowerCLI. PowerShell is a part of the Windows Management Framework and it ships with Windows client and server versions. PowerCLI extends PowerShell with commands to administer VMware environments. With PowerShell installed, you will need to obtain PowerCLI from http://www.vmware.com. The specific link is listed in the See also section of this recipe.

Once you have installed PowerCLI, you will need to build an ESXi host for this recipe. All that is required is a fresh ESXi installation from the ISO or DVD image distributed by VMware. Once installed, set an IP address on an accessible network using the console screens of the new ESXi host. The network address should be accessible from your PowerCLI workstation.

With the assumption that your ESXi host is built, the first step to administer VMware environments in PowerCLI is to connect to the ESXi host or to a vCenter server. In this chapter, you will focus on how to configure a single ESXi host. In the next chapter, you will focus on how to configure a vCenter Server and a vSphere cluster of ESXi hosts.

Getting ready

To begin, you only need to launch PowerCLI from its shortcut on the desktop or from the Start Menu. If you already had PowerCLI previously installed, you will want to check the version number to ensure that the cmdlet references throughout the book are available to you. Each version of PowerCLI builds additional native cmdlets and functionalities. To check the version you are running, open a PowerCLI prompt and run Get-PowerCLIVersion.

The recipes in this book are built and tested using VMware PowerCLI 5.5 Release 1 and have also been tested with VMware PowerCLI 5.8 Release 1, which accompanies vCloud Suite 5.8. The recipes also work on vSphere and PowerCLI 6.0 with any differences noted.

How to do it...

  1. At the PowerCLI prompt, you will execute the Connect-VIServer cmdlet as follows:
    Connect-viserver <hostname or IP>
    
  2. When executed, the code will attempt to perform a single sign-on into the ESXi host, but unless your username is root and you set the same password locally and on ESX, single sign-in will fail. You will be prompted with a normal Windows login window, which is displayed as follows, and you should log in with the root username and the password you specified during your ESXi installation:
    How to do it...
  3. Once you successfully log in to the ESXi host, a confirmation message will be displayed with the name or IP address of the ESXi host you connected to, the port, and the user you've connected to, as shown in the following example:
    Name                           Port  User
    ----                           ----  ----
    192.168.0.241                  443   root
    
  4. At this point, the PowerCLI session is connected to a host and ready to execute work.

How it works…

The Connect-VIServer cmdlet is the simplest kind of cmdlet in PowerCLI. This cmdlet initiates a connection to the vCenter or ESXi web services to allow additional commands to be passed to the server and be executed.

The Connect-VIServer cmdlet requires only the name of the host to which you want to connect. There are additional parameters that you might pass to the cmdlet, such as the protocol (HTTP or HTTPS), the username, and the password. If you prefer not to keep your password in plain text, you can also pass a PSCredentials object. The PSCredentials object contains login data to authenticate. For more information about the PSCredentials objects, type get-help about_server_authentication.

Once you execute the cmdlet, a warning will be displayed in yellow, similar to the following one:

How it works…

The warning is displayed because the certificate installed on the ESXi host is self-signed and untrusted by the computer you are connecting from. Changing an SSL certificate on ESXi hosts will be covered later in the book, but the warning can be ignored this time. The cmdlet will continue to execute even though the warning is displayed.

You can also prevent the invalid certificate errors by running the following PowerCLI cmdlet that changes the action when an invalid certificate is encountered:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false

There's more…

If you choose to join the ESXi host to Active Directory, your PowerCLI session performs a single sign-in. PowerCLI uses the credentials of your current Windows session to log in against the ESXi host or vCenter server if your account has access to the server. If your account does not have access to the server that it is attempting to connect to, a login box will be presented like our example, shown in the preceding screenshot, in this recipe.

See also

  • The Joining an ESXi host into Active Directory recipe
  • The Setting permissions on vCenter objects recipe in Chapter 2, Configuring vCenter and Computing Clusters
  • VMware PowerCLI Documentation Center and Installation Download https://www.vmware.com/support/developer/PowerCLI/
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image