Power combined: PowerCLI and OVFTool

June 16, 2013

Table of Contents

Power combined: Combining two good things creates wonders. In this post I will show how to combine the automation abilities of PowerCLI with OVFTool. You first have to get some old knowledge. Open virtualization format was designed to be a universal packaging system for virtual machines and vApps across any virtualization platform. It’s very useful and helping in importing and exporting across your VMware environments the main problem is when exporting and importing to different platforms, such a case is with the hybrid cloud use: vSphere to vCloud Director, this code is going to use a PowerCLI session and a feature in OVFTool to automate the export of our VM:

function Export-VM




        [parameter(Mandatory=$true,ValueFromPipeline=$true)] $vm,

        [parameter(Mandatory=$true)][String] $destination


    $ovftoolpaths = (“C:Program Files (x86)VMwareVMware OVF Toolovftool.exe”,”C:Program FilesVMwareVMware OVF Toolovftool.exe”)

    $ovftool = ”

    foreach ($ovftoolpath in $ovftoolpaths)


        if(test-path $ovftoolpath)


            $ovftool = $ovftoolpath



    if (!$ovftool)


        write-host -ForegroundColor red “ERROR: OVFtool not found in it’s standard path.”

        write-host -ForegroundColor red “Edit the path variable or download ovftool here: http://www.vmware.com/support/developer/ovf/”




        $moref = $vm.extensiondata.moref.value

        $session = Get-View -Id SessionManager

        $ticket = $session.AcquireCloneTicket()

        & $ovftool “–I:sourceSessionTicket=$($ticket)” “vi://$($defaultviserver.name)?moref=vim.VirtualMachine:$($moref)” “$($destination)$($vm.name).ovf”



All the good stuff happens from line 26-29:

Line 26: Get a Moref value for the VM.

Line 27: Get a PowerCLI session data

Line 28: Acquire a “clone ticket” for a session

Line 29: Run OVFTool with a session ticket, moref value, and the destination parameter. These  four lines are very key , just like Export-vApp.it will work well when you upload to vcloud.


Share on
More posts

Dedicated Servers Quick Guide

What is a Dedicated Servers? Why bother using a dedicated server over a VPS or Shared Hosting?A dedicated server is a server 100% dedicated to your website/project or business needs.

Release: Veam Backup & Replication 6.5

For those not aware, there has been a new release of the Veam Backup & Replication 6.5. It’s very interesting, the first backup solution for vSphere 5.1 and windows Server

Enhanced Storage Features on 5.1

Enhanced Storage Features on 5.1 SESMATEnhanced Storage features introduced by 5.1 VMFS File Sharing Limits In previous versions of vSphere, the maximum number of hosts which could share a read-only

Get 90% Discount

First 3 People gets the Bonus!
Don't Miss Out Our Big Sale

Get 0-90% On All
247Rack Services


The Sale Is Until The End Of March