Reader small image

You're reading from  Mastering PowerCLI

Product typeBook
Published inOct 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781785286858
Edition1st Edition
Languages
Right arrow
Author (1)
Sajal Debnath
Sajal Debnath
author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath

Right arrow

Chapter 3. Deploying vSphere Hosts

In the first chapter, we covered the basics of PowerShell and PowerCLI. Next, we covered various advanced topics, such as writing advanced functions in PowerShell and details of parameters and their different attributes. We also covered how to write help files and handle errors in PowerShell. All the previously mentioned topics were introductory topics so that you could use them to build your own advanced scripts. The primary aim of this book is to master PowerCLI, but for obvious reasons we need to master PowerShell to some extent so that we can build upon that. Since we already covered some part of it (the more advance topics of PowerShell will be covered in the upcoming chapters), let's dive into managing VMware environments using PowerCLI. We will start with the installation and configuration of the ESXi server using PowerCLI. Since there are various ways through which you can install the ESXi server, we will limit our discussion to only the portion...

Image Builder with PowerCLI


The vSphere Image Builder CLI is a process or tool used to build custom ESXi images or software bundles, which can later be installed using the update manager. It is actually a collection of PowerCLI cmdlets that gives you the power to do the earlier mentioned tasks. In most cases, VMware partners use it extensively so that they can build their own images. For example, let's assume that particular server hardware requires a few special drivers for the ESXi server to run properly on that platform. So, we have two options: either we need to install these special drivers after the installation of the ESXi server or we can preinclude them in the ESXi image itself so that we don't need to install any drivers later on. In most cases, the second approach is preferred by most hardware vendors, so you will get vanilla ESXi images from the VMware site, but if you download the ESXi image available from a server vendor site, it includes the added drivers required for the...

Using host profiles


In the preceding section, we learned how to manipulate and create custom ESXi images using PowerCLI cmdlets. So, now let's take a closer look at how to manipulate host profiles so that we can use both at a later stage in order to automate ESXi deployments. In case of VMware technologies, a host profile is a profile that stores all the configuration information of a host. We can configure an ESXi host as required and mark the host as the golden standard. Next, we create a host profile from the configuration of this host. Once the profile is ready, we can simply apply the profile to other hosts so that they can be automatically configured. This way, we can ensure consistency between host configurations across the entire infrastructure.

For this lab, we will get the following architecture:

We have a vcenter.lab.com server as a vCenter server. Under this, we have a datacenter named Datacenter. A cluster named Lab Cluster is created under Datacenter. The cluster has two ESXi...

Configuring Auto Deploy for ESXi hosts


Auto Deploy is the VMware feature that can deploy hundreds of ESXi hosts automatically. To understand Auto Deploy, let's take a look at its architecture:

Image source: http://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.vsphere.install.doc%2FGUID-9A827220-177E-40DE-99A0-E1EB62A49408.html

So, we need to work through the installation stages by navigating to Image Profile → Host Profile → Auto Deploy.

The Auto Deploy server stores the following information:

  • Image state: This is the required software that needs to be run on an ESXi server. The source of this information is the image profile, created using the Image Builder PowerCLI.

  • Configuration state: This is the configuration state of the ESXi server. This information is collected from the host profile UI, which is taken from a golden image/template.

  • Dynamic state: This is the runtime state that is generated by running the software. The source of this information is the memory of the host.

  • Virtual...

Adding hosts to a vCenter server


To add a host to a vCenter server using the PowerCLI cmdlet, we need to use the Add-VMHost cmdlet. But, for this cmdlet to run successfully, we need to first connect to a vCenter server. We can connect to a vCenter server using the Connect-VIServer cmdlet. So, let's start:

PS C:\> Connect-VIServer vcenter.lab.com –User vcadmin@lab.com –Password Vmware1!

Note that I have provided all the parameter values in the command line itself; if you omit them, then it will display a popup asking for the user ID and password.

There's a better way of providing passwords to a connection: using the –Credential option and with PSCredential. Hal Rottenberg has written very good functions to incorporate these. The functions are as follows:

The first Export-PSCredential function exports the provided credential to a credentials.enc.xml file in XML format:

function Export-PSCredential {
        param ( $Credential = (Get-Credential), $Path = "credentials.enc.xml" )

        #...

Summary


In this chapter, we discussed how to deploy hosts using image profiles and host profiles using PowerCLI. We also learned how to add a host to a vCenter server using PowerCLI.

In the next chapter, we will learn how to manage standard and advance networking in the vSphere environment in detail using PowerCLI.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering PowerCLI
Published in: Oct 2015Publisher: PacktISBN-13: 9781785286858
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.
undefined
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 €14.99/month. Cancel anytime

Author (1)

author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath