VMware Cloud Community
specator
Contributor
Contributor

Help with PowerShell script to create a Virtual Machine in vCloud Director

Hi there!

I'm a tenant in one of clouds that use vCloud Director to host it. I have a trouble with creation VM from PowerCLI. I'm not clearly understand how to define all string that I can define in vCloud Director GUI (site) and asking for help.

Here are some lines that I had wrote. Help me please to get missing lines.

 

 

$Create_VMAdmin_Username = "username"
$Create_VMAdmin_CloudServer = "vcd-site01.cloud.org"
$Create_VMAdmin_CloudOrgName = "VDC_Tenant1"
$Create_VMAdmin_CloudSite = "VDC_Tenant1_DC01"
 
$Creds_VMAdmin = Get-Credential -UserName $Create_VMAdmin_Username -Message "VM Admin Creds"
 
$NewVM_Name = "TestVM"
$NewVM_NameApp = $NewVM_Name + "-" + $GIUD
 
# Connect to cloud server
$VM_Server = Connect-CIServer -Server $Create_VMAdmin_CloudServer -Credential $Creds_VMAdmin -Org $Create_VMAdmin_CloudOrgName
# Select cloud (site)
$VM_Site = Get-OrgVdc -Server $VM_Server -Org $Create_VMAdmin_CloudOrgName -Name $Create_VMAdmin_CloudSite
$VM_Site_VApp = Get-CIVApp -OrgVdc $VM_Site
# Select template to create a new VM
$VM_Template = Get-CIVMTemplate -Server $VM_Server | Where-Object { $_.Name -like "Windows 10 Enterprise*" } | Sort-Object Name | Select-Object -Last 1
# Create a new VM
$NewVMApp = New-CIVApp -Server $VM_Server -OrgVdc $VM_Site -Name $NewVM_NameApp
$NewVM = New-CIVM -Server $VM_Server -VApp $NewVMApp -VMTemplate $VM_Template -Name $NewVM_Name -ComputerName $NewVM_Name
$NewVMNetwork = Get-CIVApp -Server $VM_Server -Name $NewVMApp | Get-CIVAppNetwork
$NewVM | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $NewVMNetwork -IPAddressAllocationMode Dhcp -Connected $true

 

So, I'm a bit confused how to size VM (set vCPU core count and RAM size)? How to check that $NewVMApp uses correct network because I did not find option to select network at all?

Labels (2)
Reply
0 Kudos
1 Reply
specator
Contributor
Contributor

Also, it's able to create a VM instance without creating vApp instance? In  a GUI I can perform this but there no suitable example of PoSh for this.

Reply
0 Kudos