Deploy Nested ESXi using PowerCLI

Virtual ESXi hosts running nested on a physical ESXi host (more commonly known as nested ESXi hosts) come in very handy when we would want to test and understand SDDC architectures, configurations, concepts and solutions from VMware. Note, nested ESXis are not supported in production environments, vSAN Witness appliance being the only exception.

You can create a virtual machine from scratch, install ESXi from datastore ISO image and build your own nested host. A more convenient and less time consuming method would be to utilize William Lam's Nested ESXi virtual appliance, which is maintained by him for every ESXi release.

I have written a simple PowerCLI script, that you may use in order to import the virtual appliance into your environment. Please note, this script was only tested with the nested ESXi 7u2 virtual appliance. This script allows you to import the vAPP with customization parameters as a input parameters to the function. With simple while loop outside the function, you can use the script to deploy multiple nested ESXi hosts using this script.

#Function to import Nested ESXi virtual appliance
#Visit William Lam's blog "" to download the required virtual aplliance
#Thanks to William Lam for creating and maintaining the nested ESXi virtual aplliances
##Funtion written ##
##05/16/2021 ##

##Begin function
function Import-nESXI {
 [bool] $vmfs,
 [bool] $ssh

#connect to target server
Connect-VIServer -Server $ServerIP -User $ServerUser -Password $ServerPass |Out-Null
$nesxconfig= Get-OvfConfiguration -ovf $nESXappPath

#set value for vapp customizations
$nesxconfig.Common.guestinfo.createvmfs.Value = $vmfs
$nesxconfig.Common.guestinfo.hostname.Value = $nESXhstname
$nesxconfig.Common.guestinfo.ipaddress.Value = $nESXIP
$nesxconfig.Common.guestinfo.gateway.Value = $nESXGW
$nesxconfig.Common.guestinfo.netmask.Value = $nESXmask
$nesxconfig.Common.guestinfo.dns.Value = $nESXdns
$nesxconfig.Common.guestinfo.ntp.Value = $nESXntp
$nesxconfig.Common.guestinfo.password.Value = $nESXpass
$nesxconfig.Common.guestinfo.ssh.Value = $ssh
$nesxconfig.Common.guestinfo.syslog.Value = $syslogip
$nesxconfig.Common.guestinfo.vlan.Value = $vlan
$nesxconfig.NetworkMapping.VM_Network.Value = $Hostnw

#import the vAPP
$vmhost= Get-VMHost -Name $targethost 
$vmhost |Import-VApp -Source $nESXappPath -OvfConfiguration $nesxconfig -Name $nESXhstname -Datastore $targetDS

#power-up VM
Get-VM -Name $nESXhstname | Start-VM |Out-Null

#Disconnect server
Disconnect-VIServer -Server $serverip -Confirm: $false


Use the script below to use the function :

Import-nESXI -ServerIP <your vcenter ip> -ServerUser <vcenter administrator user> -serverPass <vcenter password>`
-targethost <target physical hostname/ip> -targetDS <target datastore> -nESXappPath <path to where you have saved the Nested ESXi virtual appliance>`
-nESXhstname <ESXi VM name> -nESXIP <ESXi VM IP> -nESXGW <ESXi vm Gateway> -nESXmask <ESXi VM subnet mask> -nESXpass <ESXi VM root password>`
-vmfs: $true -ssh: $true

Few notes on the usage of the :

  1. The input parameter "ServerIP" was targeted for a vCenter server IP. Incase your host is not managed by a vCenter server, you can use your host IP and credentials for the corresponding input parameters, in place of a vcenter IP.

  2. Incase the target virtual host would have a DHCP network config, you do not need to use any of the network configuration input parameters like nESXIP, nESXGW, nESXmask.

  3. I have not used the input parameters like nESXdns (DNS Server IP), nESXntp (NTP Server IP) and syslogip(syslog server IP); since I do not have these devices in my home lab environment. If you have these devices, you can configure these parameters as well

  4. The parameters "VMFS" and "SSH" are boolean variables i.e. they accept $true/$false. '-VMFS:$true' builds the virtual host with VMFS datastore, '-SSH:$true' enables SSH on the target virtual host.

  5. $vlan is used to define the Host Management network vlan. If left blank, value of 0 i.e. no vlan wiil be configured.

Hope this script helps you in quick deployment of LAB SDDCs.

I will be sharing scripts to build clusters, enable cluster functions (HA/DRS/VSAN) using nested ESXi vAPPs quickly in labs/homelabs environment in my next post!

193 views0 comments

Recent Posts

See All