Earlier this year I put together a quick and nasty PowerShell Script that exports a vApp from vCloud Director using the OVFTool …for those that don’t know the OVFTool is a command line tool that has a powerful set of functions to import/export VMs and vApps from vCenter, ESXi and vCloud Director weather it be from a vCloud Air or a vCloud Air Network Provider.
You can Download and install the tool from here:
This week I needed to upload an Virtual Machine that was in OVA format and for those that have worked with vCloud Director you would know that the OVA format is not supported using the upload functionality in the current web interface. With that I thought it was a good time to round out the export using OVTTool post with an import using OVFTool post. Again, doing some research I found a bunch of posts relating to importing OVAs into vCloud Director and after working through the Admin Guide and some examples I was ready to build out a basic import command and start work on the PowerShell Script. On Windows you can run the tool from CMD but I would suggest using PowerShell/CLI as in the example below I go through building a variable.
What Info is Required:
- vCloud URL
- vCloud Username and Password
- Org Name
- vDC Name
- vApp Name
- Catalog Name
- Path to OVA
Command Line Example:
Below is a basic example of how to construct the vCloud String and use it as a variable to execute the tool.
PowerCLI C:\Program Files\VMware\VMware OVF Tool> $vCloud ="vcloud://cloud2893:*******@mycloud.mel.zettagrid.com:443?org=Org_cloud2893&vdc=DC_1120761&vapp=TurnKey&catalog=Veeam
PowerCLI C:\Program Files\VMware\VMware OVF Tool> .\ovftool C:\Users\anthony.spiteri\Downloads\turnkey.ova $vCloud
Opening OVA source: C:\Users\anthony.spiteri\Downloads\turnkey.ova
The manifest validates
Opening vCloud target: vcloud://email@example.com:443/
Deploying to vCloud vApp: vcloud://firstname.lastname@example.org:443/
Again, I’ve taken it a step further to make it easier for people to import OVAs into vCloud Director and put together another, slightly improved PowerShell Script that I have coded in to work with my old companies vCloud Zones…though this can be easily modified to use any vCloud Air Network vCD endpoint.
The output of the script can be seen below:
It’s a very basic script that gathers all the required components that make up the vCloud Source Connection String and then exports the OVA into the vCD vApp. I’ve even done a little more PowerShell improvements around password security and added a little colour.
# Adding the PowerCLI Modules
Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Clear the Screen and Make a Menu
write-host " PLEASE ENTER IN THE ZETTAGRID ZONE..." -ForegroundColor Green
write-host " 1. PERTH ZONE"
write-host " 2. SYDNEY ZONE"
write-host " 3. MELBOURNE ZONE"
$answer = read-host "Please Make a Selection"
# Set the Zone from the Menu Option Selected otherwise Exit - No Fancy While Loop
if ($answer -eq 1)
elseif ($answer -eq 2)
elseif ($answer -eq 3)
write-host "You choose....poorly"
# Get the arguments needed for the OVFTOol to Connect and Download the vApp
$username=read-host "Enter in your vCloud Username"
$password=read-host "Enter in your vCloud Password" -AsSecureString
$vCD_ORG=read-host "Enter in your vCloud Organisation"
$vDC=read-host "Enter in your vCloud Virtual Datacenter"
$vApp=read-host "Enter in your vApp"
$catalog=read-host "Enter in your vCD Catalog"
Write-Host -NoNewline -ForegroundColor Red "Enter In the Full OVA Path"
$OVA=read-host " :"
#Convert Secure Password
$password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
# Build the vCloud Connection String
#Build the vCloud Connection String to Hide Password
write-host "vCloud Connection String" $vCloud2 -ForegroundColor Yellow
# Set the OVFTool EXE and execute it with some arguments
$app = '.\ovftool.exe'
$arg1 = "$OVA"
$arg2 = "$vCloud"
& $app $arg1 $arg2
read-host "Hit Enter to Exit"
Save the code snippet as a .ps1 into the OFVTool Windows Folder and execute the script from the same location. If there are any errors with the inputs provided the OVFTool will fail with an error, but apart from that it’s a very simple straight forward way to import OVAs into any vCloud Director enabled endpoint.