By using PowerCLI cmdlets, you can automate creating different inventory objects on vSphere.

Connect to a vSphere server.

1

Get the inventory root folder and create a new folder called Folder in it.

$folder = Get-Folder -NoRecursion | New-Folder -Name Folder
2

Create a new datacenter called DC in the Folder folder.

New-Datacenter -Location $folder -Name DC
3

Create a folder called Folder1 under DC.

Get-Datacenter DC | New-Folder -Name Folder1
$folder1 = Get-Folder -Name Folder1
4

Create a new cluster Cluster1 in the Folder1 folder.

New-Cluster -Location $folder1 -Name Cluster1 -DrsEnabled -DrsAutomationLevel FullyAutomated

DRS (Distributed Resource Scheduler) is a feature that allows automatic allocation of cluster resources.

5

Add a host in the cluster by using the Add-VMHost command, and provide credentials when prompted.

$host1 = Add-VMHost -Name 10.23.112.345 -Location ( Get-Cluster Cluster1 )
6

Create a resource pool in the cluster's root resource pool.

$myClusterRootRP = Get-ResourcePool -Location ( Get-Cluster Cluster1 ) -Name Resources
New-ResourcePool -Location $clusterRootRP -Name MyRP01 -CpuExpandableReservation $true -CpuReservationMhz 500 -CpuSharesLevel high -MemExpandableReservation $true -MemReservationMB 500 -MemSharesLevel high
7

Create a virtual machine asynchronously.

$vmCreationTask = New-VM -Name VM2 -VMHost $host1 -ResourcePool MyRP01 -DiskMB 4000 -MemoryMB 256 -RunAsync

The RunAsync parameter specifies that the command runs asynchronously. This means that in contrast to a synchronous operation, you do not have to wait for the process to complete before supplying the next command at the command line.