VMware Cloud Community
CSIEnvironments
Enthusiast
Enthusiast

Import template/VM to vCloud Director catalog with PowerCLI

This is a 2 part question:

Part 1: I have about 24 virtual machines/templates in VC and would like to automate the import of these into the vCD catalog instead of doing it though the gui. I don't need the entire script just a sample function/method to use and the parameters needed Smiley Happy

I'm thinking I would need the Import-CIVApp and then use another method to convert those vApps to catelog items, just want to confirm:

http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/Import-CIVApp.html

Part 2: Once I have the VM's in a catalog, is it possible to create a  vApp, add the VM's to it and customize it (Network Settings, IP settings etc..) and then add the networking to that vApp.

Thanks!

0 Kudos
2 Replies
CSIEnvironments
Enthusiast
Enthusiast

Looks like there is another PowerCLI method you can use to do part 1 called "Import-CIVAppTemplate":

http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/Import-CIVAppTemplate.html

Connect-VIServer -Server $viserver -user $username -password $password
Connect-CIServer -Server $ciserver -user $username-password $password

$orgvdc = Get-OrgVdc "ORG VDC GOES HERE"
$vms = get-folder "FOLDER" | get-vm

$catalog = "NAME"

foreach ($vm in $vms) {

     $vm | Import-CIVAppTemplate -Name $vm.name -OrgVdc $orgvdc -Catalog $catalog

}

Disconnect-VIServer -Server $viserver -Confirm:$false
Disconnect-CIServer -Server $ciserver -Confirm:$false

Only thing I can't work out is how to create the Catalog if it doesn't exist. The catalog switch is optional and if you do not specify it, it imports to "vApp Templates" under the "Administration" tab of your Organization.

Making progress!

0 Kudos
jake_robinson_b
Hot Shot
Hot Shot

Something like this?

$newCatalog = New-Object vmware.vimautomation.cloud.views.admincatalog
$newCatalog.name = "Private Catalog"
$newCatalog.IsPublished = $false
$newCatalog.description = "Automatically Generated by Script"
$newCatalog.owner = New-Object VMware.VimAutomation.Cloud.Views.Owner
$newCatalog.owner.user = New-Object vmware.vimautomation.cloud.views.reference
$newCatalog.owner.user.href = (Get-CIUser $global:DefaultCIServers[0].user).href
$newCatalog.owner.user.name = $global:DefaultCIServers[0].user
$org.extensiondata.CreateCatalog($newCatalog)

Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
0 Kudos