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:”




        $moref = $vm.extensiondata.moref.value

        $session = Get-View -Id SessionManager

        $ticket = $session.AcquireCloneTicket()

        & $ovftool “–I:sourceSessionTicket=$($ticket)” “vi://$($$($moref)” “$($destination)$($”




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 will work well when you upload to vcloud.

Leave a Reply

You must be logged in to post a comment.