Infrastructure Adventures


VCP5 Blueprint with PowerCLI – Objective 1.2 – Install and Configure VMware ESXi

Filed under: Virtualization — Tags: , , , , , , — Joe Keegan @ 7:08 PM

See the Series page for more info on the VCP5 Blueprint with PowerCLI series and for links to it’s other parts. Please note that I do not think there is any PowerCLI on the VCP 5 test (except maybe for Auto deploy), this is simply an exercise at looking at how to accomplish these tasks using PowerCLI.

Deploy an ESXi host using Auto Deploy

There has been a lot written on Auto Deploy and I would recommend the following posts for info on this feature.

Configure NTP on an ESXi Host

Add an NTP server to a single host

Add-VmHostNtpServer -NTPServer <NTP Server IP> -VMhost <ESXi Server>

remove an NTP server from a single host

remove-VmHostNtpServer -NTPServer <NTP Server IP> -VMhost <ESXi Server>

Add a NTP server to all hosts in a Cluster

get-cluster  | get-vmhost | Add-VmHostNtpServer -NTPServer <NTP Server IP>

Or for all hosts in a datacenter

get-datacenter  | get-vmhost | Add-VmHostNtpServer -NTPServer <NTP Server IP>

Start NTP on a single host

Get-VMHostService -VMhost <ESXi Server> | where {$_.key -eq "ntpd"} | Start-VMHostService

Start NTP on all hosts in a cluster

get-cluster  | get-vmhost | Get-VMHostService | where {$_.key -eq "ntpd"} | Start-VMHostService

Configure NTP to start automatically on a single host

Get-VMHostService -VMhost <ESXi Server> | where {$_.key -eq "ntpd"} | Set-VMHostService -Policy automatic

On all hosts in a cluster

get-cluster  | get-vmhost | Get-VMHostService | where {$_.key -eq "ntpd"} | Set-VMHostService -Policy automatic

Configure DNS and Routing on an ESXi Host

Add DNS server, domain name and serach domain to an ESXi server

$vmHostNetworkInfo = Get-VmHostNetwork -VMHost <ESXi Server>
Set-VmHostNetwork -Network $vmHostNetworkInfo -DNSAddress <DNS Server IPs> -DomainName <domain name> -SearchDomain <Search domains>

Where <DNS Server IPs> and <Search domains> can be comma separated lists of IPs/Domains

And to do the same thing for all hosts in a cluster

$vmHostNetworkInfo = get-cluster  | get-vmhost | Get-VmHostNetwork
Set-VmHostNetwork -Network $vmHostNetworkInfo -DNSAddress <DNS Server IPs> -DomainName <domain name> -SearchDomain <Search domains>

Setting/Changing the default gateway for an ESXi hos

$vmHostNetworkInfo = Get-VmHostNetwork -VMHost <ESXi Server>
Set-VmHostNetwork -Network $vmHostNetworkInfo -VMKernelGateway <Gateway IP>

VMHostNetworkInfo includes both a VMKernelGateway & ConsoleGateway property, but only the VMKernelGateway is used since ESXi does not have a service console.

You can view the DNS and routing settings via the command below, I find list formatting is useful for this info.

Get-VMHostNetwork -vmhost <ESXi Server>  | fl

Enable/Configure/Disable Hyperthreading

Checking to see if Hyperthreading is enabled

get-vmhost <ESXi Server> | Select-object HyperthreadingActive

Disable Hyperthreading on a single host

## host upon which to act
$strMyHostName = ""
## get the View object for the HostCpuSchedulerSystem
$viewHostCPUSchedulerSystem = Get-View (Get-View -ViewType HostSystem -Property ConfigManager.CpuScheduler -Filter @{"Name" = $strMyHostName}).ConfigManager.CpuScheduler
## disable hyperthreading

There doesn’t seem to a single cmdlet that can be used to configure hyperthreading so I grabbed the script above by mattboren in this VMware Communities thread. As mentioned in the thread this change only takes effect “next time the CPU scheduler starts”, which I assume means it requires a reboot.

Enable/Size/Disable memory compression cache

Memory compression is an advanced setting which can be manipulated via the Set-VMHostAdvancedConfiguration cmdlet.

Memory compression is enabled by default, so to disable it on a single ESX server.

Set-VMHostAdvancedConfiguration -VMhost <ESXi Server>  -Name Mem.MemZipEnable -Value 0

Change the value to a 1 to enable compression.

To see the all the memory compression settings.

Get-VMHostAdvancedConfiguration -VMhost <ESXi Server>  -Name *zip*

License an ESXi host

The only cmdlet specifically related to licensing is the Get-LicenseDataManager cmdlet, which is used with automatic or bulk licensing (see below). For licensing a single host you will need to use the get-view cmdlet to interface withe the vSphere API.

The following script can be used to assign a license to a specific ESXi host.

$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager
$hostSys = get-vmhost <ESXi server> | get-view
$Uuid = $hostSys.Config.Host.Value
$DisplayName = $
$licAssignMgr.UpdateAssignedLicense($Uuid, $LicKey,$DisplayName)

You can use the code below to find out what vSphere license has been assigned.

$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager
$hostSys = get-vmhost <ESXi server> | get-view
$Uuid = $hostSys.Config.Host.Value

There are some  good posts out there on manipulating licensing with PowerCLI and if you are interested I would suggest you check these out. Most refer to vSphere 4, but apply equally to vSphere 5.

Another option is to use automatic or bulk licensing. With this method you associate a license to a container, such as a data center, cluster or folder, and then each host that is placed into that container is assigned the associated license. You use the Get-LicenseDataManager cmdlet for this method and it’s ideal for deployments using Auto Deploy. See Set Up Bulk Licensing from the vSphere documentation for more info.

Extra Credit

Surprisingly some of the initial tasks that you would do in a new VMware deployment are not specifically called out in the VCP5 Blueprint. Tasks such as creating a data center, adding ESXi hosts to vCenter, etc. So I’ve documented these tasks here.

Creating a Datacenter

Add a new datacenter to vCenter’s root.

New-Datacenter -Location Datacenters -Name <DC Name>

The location Datacenters is the root folder for vCenter.

Adding a ESXi host to vCenter

Add-VMHost -Name <ESXi Server Name or IP>  -Location <Location>  -User <Username>  -Password <Password>  -Force

<Location> can be a Datacenter, folder or cluster (possibly others?). The -Force option is needed if the ESXi server’s certificate is self-signed.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme. Create a free website or blog at


Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: