Few days back I wrote CREATE VIRTUAL DATACENTER AND ADD ESXI HOST ON VCENTER SERVER using vSphere web client. That was completely graphical user interface GUI way to perform the task. Now I will be performing same task using VMware vSphere Powercli tool. I have downloaded it from http://www.vmware.com and installed also before running powercli tool need to enable execution policy for running powershell ps1 files (set-executionpolicy unrestricted) or else you may end up with error POWERCLI INITIALIZE-POWERCLIENVIRONMENT.PS1 CANNOT BE LOADED BECAUSE RUNNING SCRIPTS IS DISABLED. It helps to run script and create vsphere environment in Powershell, in the background its importing all vmware modules.
Once all the necessary changes done Find Powercli and run it, and very first task is to connect Vcenter server and create connection the same way you connect through vSphere client or vsphere web client. First command I am running is Connect-VIserver, Green fields need to be changed as per one's environment., Once executed it popups for password if they are authenticated successfully I can see connection is made and connected to vCenter using provided username. (I got certificate warning but i can ignore it)
Next execute below command to create a new virtual datacenter, I am storing all the info in powershell variable $Datacenter so I can use it later, In case if I want to use existing datacenter I will run command $Datacenter = Get-Datacenter -Name MySecondDatacenter instead of below.
$Datacenter = New-Datacenter -location (Get-Folder -NoRecursion) -Name MySecondDatacenter
Once new datacenter is created add esxi host to the datacenter using below command, I was prompted for root username and password.
Add-VMHost -Name 'Esxi002.vcloud-lab.com' -Location $Datacenter -Credential (Get-Credential root) -Force -Confirm:$false
Once the task is successful I can login to vsphere web client and check the recent tasks and inventory object if everything is fine.