Pages

Sunday, February 9, 2014

Creating Datacenters, Clusters, and adding ESXi hosts to VMware vCenter 5.x with PowerCLI

There are times when I stop and think about how many VMware vSphere clusters I’ve deployed over the last few years and how many mouse clicks I’ve had to do just to create the datacenter and cluster objects in vCenter then subsequently adding all the hosts to the clusters.  I generally don’t mind adding a few hosts via the GUI but when there are 10 or more hosts, the task becomes repetitive and mundane. 

I realized how inefficient this was last year so I went ahead and started using PowerCLI to create the datacenter, the clusters and finally bulk add the hosts.  Seeing how I use these cmdlets quite often and never wrote a blog post, I figure I’d write one so I can access these cmdlets anywhere.

Creating a new Datacenter

The PowerCLI cmdlet to create a new datacenter is: New-Datacenter

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FNew-Datacenter.html

image

To create a new datacenter object, simply execute the following:

New-Datacenter -Location (Get-Folder -NoRecursion) -Name “Toronto”

Creating a new Cluster

The PowerCLI cmdlet to create a new datacenter is: New-Cluster

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FNew-Cluster.html

image

To create new cluster objects with HA enabled, simply execute the following:

New-Cluster -Location <DatacenterName> -Name Desktops -HAEnabled

New-Cluster -Location <DatacenterName> -Name Servers -HAEnabled

Add ESXi hosts to clusters

The PowerCLI cmdlet to create a new datacenter is: Add-VMHost

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FAdd-VMHost.html

image

add-vmhost esxi-09.someNetwork.net -location "Desktops" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-12.someNetwork.net -location "Desktops" -user root -password 3edc@WSX -force:$true

add-vmhost esxi-01.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-02.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-03.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-04.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-05.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-06.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-07.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-08.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-55.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true
add-vmhost esxi-56.someNetwork.net -location "Servers" -user root -password 3edc@WSX -force:$true

Definitely sure beats manually adding the hosts via the vSphere Client GUI.

No comments: