Configuring the Basic Settings of an ESXi Host with PowerCLI

1

Configuring the Basic Settings of an ESXi Host with PowerCLI

In this chapter, you will cover the following topics: Connecting to an ESXi host or vCenter instance Getting the VMware host object Joining an ESXi host into Active Directory Enabling services and setting security profiles Setting network configuration Creating datastores on an ESXi host Configuring syslog settings on a host Joining an ESXi host to vCenter Creating a configuration script to set all properties uniformly

Introduction

Initially automation doesn't save time. To really get the benefits of automation, you must invest the time upfront to create scripts that you'll use time and again. In this chapter, you'll take your first ESXi host that has been installed and has an IP address configured on it and you will build continually from there. This chapter will take an administrator through the basic configuration tasks needed to perform initial configuration, join them to vCenter, and get it into an operational state. At the end of this chapter, all these steps build into a scripted configuration that can be executed against new hosts in the future.

Connecting to an ESXi host or vCenter instance

To begin working with PowerCLI, you must first have PowerShell installed and available on the system you want to run PowerCLI. PowerShell is 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 . The specific link is listed in the See also... section of this recipe.

Once you have installed PowerCLI, you will need an ESXi host built 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 administering VMware environments in PowerCLI is to connect to the ESXi host or to a vCenter server. In this chapter, you will focus on configuring a single ESXi host and in the next chapter you will focus on configuring a vCenter Server and 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 cmdlets references throughout the book are available to you. Each version of PowerCLI builds additional native cmdlets and functionality. 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 version 5.5 Release 1 and have also been tested with PowerCLI version 5.8 Release 1.

How to do it...

1. At the PowerCLI prompt, you will execute the Connect-VIServer cmdlet.

Connect-viserver

2. When executed, the code will attempt to 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, displayed below, and you should login with the root username and password you specified during your ESXi installation.

2

Insert Image 3724EN_01_01.png

3. Once you successfully log into 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 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. The cmdlet initiates a connection to the vCenter or ESXi web services to allow for additional commands to be passed to the server and executed.

The Connect-VIServer cmdlet requires only the name of the host to which you want to connect. There are additional parameters that you may 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 PSCredential objects, type get-help about_server_authentication.

Once you execute the cmdlet, a warning will be displayed in yellow like the one below.

3

Insert Image 3724EN_01_02.png

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 SSL certificate on ESXi hosts will be covered later in the book, but the warning may be ignored at this time. The cmdlet will continue to execute even though the warning is displayed. You may also prevent the invalid certificate errors by running the following PowerCLI cmdlet, which 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 login against the ESXi host or vCenter server, if your account has access. If your account does not have access to the server it is attempting to connect, a login box will be presented like our example in this recipe.

See also

Joining an ESXi host into Active Directory, Chapter 1 Setting permissions on vCenter objects, Chapter 2 VMware PowerCLI Documentation Center & Installation Download



4

Getting the VMware host object

After connecting to a host to manage, other cmdlets become available. The first concept that you will need to become aware of are PowerShell objects. Objects are defined data obtained from commands run in PowerShell and PowerCLI. To perform configuration on an ESXi host, the commands you run will need a host object specified. In this recipe, you will learn how to obtain a VMHost object.

Getting ready

To begin with, open a PowerCLI window and connect to an ESXi host or vCenter instance.

How to do it...

1. To retrieve an ESXi host object, PowerCLI is straightforward.

Get-VMHost

2. After running the Get-VMHost cmdlet, an object containing one or more ESXi hosts is returned. You are connecting to a single ESXi host in this example, running Get-VMHost returns host object with a single host. If you were connecting against a vCenter instance, Get-VMHost with no other arguments would return an object containing all of the hosts managed by vCenter. When running against vCenter, you may specify a filter with the Get-VMHost cmdlet in order to find one or more hosts that match the specified pattern.

Get-VMHost esxhost* Get-VMHost VMHOST1

3. Instead of having to call the Get-VMHost cmdlet each time you need to get the ESXi host, you can store the host object in a variable. PowerShell variables are specified as a $ followed by a name. Below is an example for our ESXi host:

$esxihost = Get-VMHost

How it works...

To examine more about the VMHost object, you can use the Get-Member cmdlet with the variable you have just defined. To use Get-Member, you will call the VMHost object by typing the $esxihost variable. Then, you pipe the object into the Get-Member cmdlet.

$esxihost | Get-Member

PowerCLI is an extension of PowerShell that is used specifically for VMware product management. PowerShell is an object-based language meaning that it uses the concept of encapsulating both data and operations within an object data type, which is a familiar

5

object-oriented programming concept. Objects have defined data areas and may include functions that perform operations on the data in the object. The output from the cmdlet shows all of the data contained in the Property elements in the object. The object also includes a number of methods. The methods are used to manipulate the data in the object.

PowerCLI> $esxihost | Get-Member

Insert Image 3724EN_01_03.png

You can call a method by using dot notation and by calling the method name followed by parenthesis, like the example below.

PowerCLI> $esxihost.ConnectionState.ToString() Connected

6

In this example, the State property is an object inside of the VMHost object but the ToString() method converts the output to a string.

Now that the ESXi host object is stored in a variable, you can proceed with other cmdlets for configuration and run them using the host object to perform configuration.

There's more...

Get-VMHost has other applications beyond just returning the VMHost object to use. Like all other Get- cmdlets, this cmdlet can be used to find a host in a particular configuration or state. You can use Get-VMHost to find hosts assigned to a particular location in vCenter using the -Location parameter, you may want to find hosts that have been assigned a particular Tag in vSphere using the ?Tag parameter or you may want to find the host running a particular VM with the -VM parameter. Another interesting use case is specifying the -Datastore parameter to find all the hosts that have a particular datastore connected.

Get-VMHost is just one of many cmdlets that work with VMHost objects. Others will be explored in the "Configuring vCenter and computer clusters," Chapter 2.

See also

Setting up folders to organize objects in vCenter, Chapter 2 Creating basic reports of VM properties from VMware Tools and PowerCLI,

Chapter 3

Joining an ESXi host into Active Directory

As mentioned in the connecting section, joining an ESXi host to Active Directory offers the ability to connect without entering credentials for administrators. Active Directory is a Windows implementation of Lightweight Directory Access Protocol (LDAP). Active Directory contains accounts for users, computers, and groups. Active Directory runs on a Windows Server that has the Active Directory role installed and that has been "promoted" to become a domain controller. To perform this recipe, you will need at least one Active Directory server available on the network with the ESXi host.

Seamless authentication is one of the biggest reasons to join a host to Active Directory. But beyond single sign-on, once the ESXi host is connected to Active Directory, groups in the directory can be leveraged to grant permissions to the ESXi host. If you do not have Active Directory installed and do not wish to, you may skip this recipe and move on to other topics of host configuration without any impact to future recipes.

7

Getting ready

PowerCLI has Get-VMHostAuthentication and Set-VMHostAuthentication, two cmdlets to deal with host authentication. To get ready to setup authentication, open a PowerCLI window and connect to a single ESXi host.

How to do it...

1. Because the cmdlets require a VMHost object, you'll again be using the GetVMHost to either populate a variable or to pipe the object to the next object. The first step is to obtain a VMHost object for our target ESXi host.

$esxihost = Get-VMHost 192.168.0.241

2. Once you have your VMHost object, you can look at setting authentication. The Set-VMHostAuthentication cmdlet needs to be executed. The cmdlet requires several parameters to join a ESXi host to domain. The syntax needed is displayed follows:

$esxihost | Get-VMHostAuthentication | SetVMHostAuthentication -JoinDomain -Domain domain.local -user username -password *****

3. Executing the cmdlet will prompt you to confirm that you want to join this host to the domain specified. If you answer Y, the cmdlet will continue and execute the operation.

Perform operation? Joining VMHost '192.168.0.241' to Windows Domain 'domain.local'. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):Y

Domain -----DOMAIN.LOCAL

DomainMembershipStatus ---------------------Ok

TrustedDomains --------------

How it works...

One of the first things you notice about this recipe is that there is an extra GetVMHostAuthentication cmdlet in the middle of the command line. Why does it need to perform Get before performing the Set? It would seem that you can simply pipe the VMHost object into cmdlet to specify your target host and the cmdlet will execute, but as you try that below, PowerCLI displays an error.

$esxihost | Set-VMHostAuthentication -JoinDomain -Domain domain.local -user username -password *****

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download