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
- Retrieve a target datastore ID.
$targetDatastore = Invoke-ListDatastore -Names 'local-0'
- Retrieve a target folder ID.
$targetFolder = Invoke-ListFolder -Names 'vm'
- Retrieve a target host ID.
$targetHost = Invoke-ListHost -Names '10.185.41.87'
- Prepare the virtual machine placement specification.
$placementSpec = Initialize-VMPlacementSpec -Folder $targetFolder.folder -Datastore $targetDatastore.datastore -VarHost $targetHost.host
- Prepare the virtual machine create specification.
$vmCreateSpec = Initialize-VMCreateSpec -Name 'TestVM' -GuestOS WIN_31 -Placement $placementSpec
- Invoke the
CreateVM
API operation.
Invoke-CreateVM -VMCreateSpec $vmCreateSpec