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...
You're reading from Mastering 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...
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...
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:
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...
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" ) #...
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.