VMware Cloud Community
pwmiller
Enthusiast
Enthusiast

Sample Script: Creating an Empty vApp with vCloud PowerCLI

Hi Everyone,

The New-CIVApp cmdlet does not allow us to create empty vApps (which can be useful when templating out network configurations, for example). This shortcoming can be overcome by calling the "ComposeVApp" method of a vDC directly. In case anybody else runs into this same problem, I've included my script. Note that it uses the first created organization vDC, so ymmv.

I also realize that I could probably get the vDC directly instead of going through ExtensionData, but I think that this illustrates that "otherwise hidden" parameters can be discovered rather easily through this object ("Get-Member" is your friend!)

$newvapp = New-Object VMware.VimAutomation.Cloud.Views.ComposeVAppParams

$newvapp.Name = "My New vApp"

$newvapp.Description = "An empty vApp"

$result = (DefaultCIServers[0].ExtensionData.OrganizationReferences.OrganizationReference | Where-Object {$_.Name -like "organization name"}).GetCIView().VDCs.VDC[0].GetCIView().ComposeVApp($newvapp)

$result.tasks.task.wait($null)

Write-Host "$($result.tasks.task.Operation) $($result.tasks.task.status)

Reply
0 Kudos
1 Reply
jfrmilner
Contributor
Contributor

Thanks.

Minor typo on Line:

$result = (DefaultCIServers[0].ExtensionData.OrganizationReferences.OrganizationReference | Where-Object {$_.Name -like "organization name"}).GetCIView().VDCs.VDC[0].GetCIView().ComposeVApp($newvapp)

should be

$result = ($DefaultCIServers[0].ExtensionData.OrganizationReferences.OrganizationReference | Where-Object {$_.Name -like "organization name"}).GetCIView().VDCs.VDC[0].GetCIView().ComposeVApp($newvapp)

Reply
0 Kudos