You can create virtual machines in vCenter Server by using the vSphere Automation SDK for PowerShell.

Prerequisites

Verify that you are connected to a vSphere Automation API server.

Procedure

  1. Retrieve a target datastore ID.
    $targetDatastore = Invoke-ListDatastore -Names 'local-0'
    
  2. Retrieve a target folder ID.
    $targetFolder = Invoke-ListFolder -Names 'vm'
    
  3. Retrieve a target host ID.
    $targetHost = Invoke-ListHost -Names '10.185.41.87'
    
  4. Prepare the virtual machine placement specification.
    $placementSpec = Initialize-VMPlacementSpec -Folder $targetFolder.folder -Datastore $targetDatastore.datastore -VarHost $targetHost.host
    
  5. Prepare the virtual machine create specification.
    $vmCreateSpec = Initialize-VMCreateSpec -Name 'TestVM' -GuestOS WIN_31 -Placement $placementSpec
    
  6. Invoke the CreateVM API operation.
    Invoke-CreateVM -VMCreateSpec $vmCreateSpec