In this series to access nested ESXi lab I need a Jump Server, which I will setup one using this PowerCLI script, Below is the output for it. This Jump server Windows VM is deployed using existing template. It is customized using specs, IP assigned, Added two network adapters one in LAN and another in the WAN.
Make sure you have following this Complete Series for proper configuration:
Part 1 How to Build a Nested ESXi Lab: The Ultimate Networking Guide
Part 2 Nested ESXi Networking with VyOS Virtual Router: A Step-by-Step Guide
Part 3 Deploying a Dual-Homed Jump Server for Secure Nested Lab Access
Here is the simple PowerCLI script which helps you to deploy and configure Windows Virtual Machine from template.
Download this Deploy_VM_And_Configuration_PowerCLI.ps1 here or it is also available on github.com/janviudapi.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
$vCenterServer = 'dccomics.vcloud-lab.com' $vCenterUsername = '[email protected]' $vCenterPassword = 'Computer@123' $templateName = '_template_windows_2022' $newVMName = 'vm01-jumpserver' $vmHost = 'superman.vcloud-lab.com' $wanNetworkName = 'VM Network' $datastore = 'Daily-Planet01-6T' $folder = 'VCF' $osCustomizationSpecName = 'windows-os-custom-spec' $wanIpAddress = '192.168.34.25' $wanSubnetMask = '255.255.255.0' $wanDefaultGateway = '192.168.34.1' $wanDns = @('192.168.34.11') #LAN network information $lanNetworkName = 'Green_LAN_trunk_Nesting' $lanIpAddress = '172.16.0.25' $lanSubnetMask = '24' $lanDefaultGateway = '172.16.0.1' $lanDns = @('172.16.0.11') $newVMGuestUser = 'administrator' $newGuestPassword = 'Computer@123' Import-Module VMware.VimAutomation.Core Write-Host "- Login vCenter: $vCenterServer" Connect-VIServer -Server $vCenterServer -User $vCenterUsername -Password $vCenterPassword | Out-Null Write-Host "- Checks before cloning task" -BackgroundColor DarkCyan try { $vmExist = Get-VM $newVMName -ErrorAction Stop if ($vmExist) { Write-Host " - VMName exists: $newVMName" -BackgroundColor DarkCyan break } $tempOSCustomSpec = Get-OSCustomizationSpec -Name "Temp_$osCustomizationSpecName" -ErrorAction Stop if ($tempOSCustomSpec) { Get-OSCustomizationSpec -Name "Temp_$osCustomizationSpecName" | Remove-OSCustomizationSpec } } catch { $_.Exception.GetType().FullName Write-Host " - VMName not exist: $newVMName or OS customization spec not exist" -BackgroundColor DarkCyan } Write-Host "- Check existing configuration Template and Os Customiziation Spec" $template = Get-Template -Name $TemplateName $baseSpec = Get-OSCustomizationSpec -Name $osCustomizationSpecName Write-Host "- Create temporary Os Customiziation Spec" $tempSpec = $baseSpec | New-OSCustomizationSpec -Name "Temp_$osCustomizationSpecName" -Type NonPersistent Write-Host "- Set IP addres to temporary Os Customiziation Spec" $tempSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $wanIpAddress -SubnetMask $wanSubnetMask -DefaultGateway $wanDefaultGateway -Dns $wanDns | Out-Null Write-Host "- Start Cloning new virtual machine: $newVMName" $newVM = New-VM -Name $newVMName -VMHost $vmHost -Location $folder -Template $template -OSCustomizationSpec $tempSpec -NetworkName $wanNetworkName -Datastore $datastore -DiskStorageFormat Thin Write-Host "- Poweron virtual machine: $newVMName" $newVM | Start-VM | Out-Null Start-Sleep -Seconds 90 Write-Host "- Remove temporary customization spec: Temp_$osCustomizationSpecName" Get-OSCustomizationSpec -Name "Temp_$osCustomizationSpecName" | Remove-OSCustomizationSpec -Confirm:$false | Out-Null Write-Host "- Os Customization in Progress | Test Ping $ipAddress" while (-not(Test-Connection -IPv4 $wanIpAddress -Quiet -Count 1)) { '\','|','/','-','*' | ForEach-Object { Write-Host "`r- VM configuration in progress: $_ " -NoNewline Start-Sleep -Milliseconds 200 } } Write-Host "`r- VM is created | Waiting 2.5 minutes to complete sysprep and reboot" Start-Sleep -Seconds 150 Write-Host "- Add second network adapter in portgroup: $lanNetworkName" $newVM | New-NetworkAdapter -NetworkName $lanNetworkName -WakeOnLan -StartConnected -Type Vmxnet3 | Out-Null $mask = [IPAddress]$lanSubnetMask $prefix = ([Convert]::ToString([uint32]$mask.Address,2) -replace '0').Length $ethName = 'Ethernet1' $scriptText = @" New-NetIPAddress -InterfaceAlias $ethName -IPAddress $lanIpAddress -PrefixLength $prefix -DefaultGateway $lanDefaultGateway Set-DnsClientServerAddress -InterfaceAlias $ethName -ServerAddresses $lanDns route add 10.10.10.0 mask 255.255.255.0 172.16.0.1 route add 10.10.20.0 mask 255.255.255.0 172.16.0.1 "@ Write-Host '- Configure VM settings' $newVM | Invoke-VMScript -GuestUser $newVMGuestUser -GuestPassword $newGuestPassword -ScriptText $scriptText -ScriptType Powershell Write-Host "- Logout vCenter: $vCenterServer" Disconnect-VIServer -Server * -Confirm:$false |
After deploying virtual machine, below is the network adapter configuration of the jump server VM.
In between if you want access to other networks you can add route using below commands to make them reachable .
For windows
route add -p 10.10.10.0 mask 255.255.255.0 172.16.0.1
route add 10.10.20.0 mask 255.255.255.0 172.16.0.1
For Linux
ip route add 10.10.0.0/16 via 172.16.0.1 dev eth1
Useful Articles
PART 1 : BUILDING AND BUYING GUIDE IDEAS FOR VMWARE LAB
PART 2 : BUILDING AND HARDWARE BUYING GUIDE IDEAS FOR VMWARE LAB
PART 3 : MY VSPHERE LAB CONFIGURATION ON VMWARE WORKSTATION
PART 4 : CONFIGURING VMWARE WORKSTATION NETWORKING IN HOME LAB
PART 5 : CONFIGURING STORAGE IN VMWare WORKSTATION FOR OPTIMAL SPEED
PART 6 : CONFIGURE VMWARE WORKSTATION TO SAVE SSD SPACE AND TIME
PART 7 : CREATING NESTED VMWARE ESXI SERVER VM IN HOMELAB ON VMWARE WORKSTATION
PART 8 : CPU COOLING SOLUTION FOR MY HOME LAB ON VMWARE WORKSTATION
Part 9: Guide to building a Home Lab


