There are quite a few clicks needed to add a host to vCenter. If you are deploying multiple hosts to your environment you have many clicks ahead. You should script it! This PowerShell script will make adding multiple hosts to vCenter easy!
Let’s see it in action!
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 |
##################################################################### # Load VMware Plugins and connect to vCenter ##################################################################### Add-PSSnapin vmware.vimautomation.core ## Enter your vCenter here connect-viserver -server LABVC01.virtuallyboring.com ######################################################################## # Add Multiple Hosts to vCenter ######################################################################## # Variables ## You can use comma separated names or change to pull from a text file. Your pick. $ESXiHosts = "ESXi01.virtuallyboring.com" , "ESXi02.virtuallyboring.com" , "ESXi03.virtuallyboring.com" ## Enter the name of a Data Center or Host Cluster $ESXiLocation = "Nested ESXi Cluster" # Start Script $credentials = Get-Credential -UserName root -Message "Enter the ESXi root password" Foreach ($ESXiHosts in $ESXiHosts) { Add-VMHost -Name $ESXiHosts -Location $ESXiLocation -User $credentials.UserName -Password $credentials.GetNetworkCredential().Password -RunAsync -force Write-Host -ForegroundColor GREEN "Adding ESXi host $ESXiHosts to vCenter" } # End Script |
In my environment I deployed three new ESXi hosts (ESXi01-03.virtuallyboring.com) and I want to add them to my cluster named Nested ESXi Cluster:
Open the script in PowerShell ISE as we need to update a few variables highlighted in yellow:
- Update the vCenter name to your vCenter name
- In the Variables section update $ESXiHosts to the names of the hosts you want to add
- Update the $ESXiLocation to the name of the Data Center or Host Cluster you want the hosts added to
You are now ready to run the script! You should receive a popup requesting the root credentials of the ESXi hosts. The password never enters plain text and remains encrypted and secure (See screenshot below):
Popup requesting ESXi root credentials:
Over in vCenter you should see Add Host tasks with the hosts appearing under your specified location!
This script should make it very easy to add multiple hosts to your environment in one swoop!
Hi,
This is krish here please update me after adding .vmx file into inventory the the vm should power on automatically using powershell
If all of my hosts have unique passwords what would I have to change?