Creating multiple vCloud vApps with PowerCLI

Sometimes when I’m testing in vCloud, I’ll find myself going through the vCloud vApp wizard over and over again.   Here is some PowerCLI code to create vApps from the command line.  It’s pretty basic right now and I plan on adding more functionality to it later.

# Your environmental variables

$vCloudName = 'cloud51.vmware.local'
$orgName = 'vmware'
$catalogName = 'Linux'
$orgVdcName = 'vmware-payg-prod1-vc5c'
$vAppTemplateName = 'Linux Minimal vApp'
$startPrefix = 1
$endPrefix = 3

connect-ciserver $vCloudName # connect to vCloud
$org = Get-Org $orgName # get the org
$orgvdc = $org | Get-OrgVdc $orgVdcName # get the org vDC
$catalog = get-org admin | Get-Catalog $catalogName # get the catalog where our vApp Template is
$vAppTemplate = $catalog | Get-CIVAppTemplate $vAppTemplateName # get the vApp Template from the catalog

# Create the vApps
($startPrefix..$endPreFix) | foreach { New-CIVApp "$($vAppTemplateName)$($_)" -OrgVdc $orgvdc -VAppTemplate $vAppTemplate }

You may want to connect the vApps to a network. This will connect every NIC on every VM in the vApp to a single network. At least it should, I haven't tested it with call cases.

# Your environmental variables
$vCloudName = 'cloud51.vmware.local'
$orgName = 'vmware'
$orgNetworkName = 'external-vlan5'
$catalogName = 'Linux'
$orgVdcName = 'vmware-payg-prod1-vc5c'
$vAppTemplateName = 'Linux Minimal vApp'
$startPrefix = 1
$endPrefix = 3

connect-ciserver $vCloudName # connect to vCloud
$org = Get-Org $orgName # get the org
$orgNetwork = $org | Get-OrgNetwork $orgNetworkName # get the org network we will connect the vApp to
$orgvdc = $org | Get-OrgVdc $orgVdcName # get the org vDC
$catalog = get-org admin | Get-Catalog $catalogName # get the catalog where our vApp Template is
$vAppTemplate = $catalog | Get-CIVAppTemplate $vAppTemplateName # get the vApp Template from the catalog

# Create the vApps
($startPrefix..$endPrefix) | foreach { 
 $vApp = New-CIVApp "$($vAppTemplateName)$($_)" -OrgVdc $orgvdc -VAppTemplate $vAppTemplate
 $vAppNetwork = New-CIVAppNetwork -Direct -ParentOrgNetwork $orgNetwork -VApp $vApp
 $vApp | Get-CIVM | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $vAppNetwork -IPAddressAllocationMode POOL
}

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s