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

{

    param

    (

        [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/”

    }

    else

    {

        $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.

Home

Share on
Facebook
Twitter
LinkedIn
Pinterest
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.

vCheck6 Utility Commands

There is a new release of the vCheck6 and those with need for more info they can visit the vCheck 6 release page and ensure to visit the vCheck plugins

How to be a PowerCLI Ninja

Many people are becoming curious about the powershell/powerCLI and how to become a Powershell/PowerCLI ninja and I think the following tips will help one go a long way to become

🎉 New Year’s Special🎉
50% OFF for Life!

🔥 DELL Bare-metal Dedicated Server in New York

🔹  Intel Gold 80 Cores
🔹  23TB SSD Flash +
🔹1TB NVMe (W RAID)
🔹 1TB DDR4 RAM 
🔹 10Gbps Redundant Uplinks 
🔹 10 IPv4 + IPv6 Addresses Included 

💲 Just $699/month – 50% OFF FOR LIFE! (Reg $1399/month)
🚀 Zero Setup Costs | Flexible OS: Ubuntu, Proxmox, ESXi, Windows, etc.

✅ Reserve Risk-Free! 30-Day Money-Back Guarantee
💡 100% Uptime Assurance – Enterprise-Grade Hardware 

🖥 Ideal for Virtualization, Data-Intensive Apps, & High Traffic Sites

Use coupon code at checkout for the discount to apply FBHEO3023EJFB
⚡ Limited Availability – Don’t Miss Out!

Get 90% Discount

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

Get 0-90% On All
247Rack Services

247Rack

The Sale Is Until The End Of March