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.

Managing Amazon EC2 VMs from the vSphere client

Automation and mulitplatformsupport is gaining more and more popularity. We already a multihypervisor management tool from VMware for Hyper-V and VMware. From vCloud Automation Center you can create workloads in

Sharing vApps in vCloud with PowerCLI

Some times vCloud Directors give the organization users grainy control over the the level of access users have to vApps , this is all controlled through the the vCloud API

A Look at vCenter 5.5 SSO RC Installation

vCenter single sign on (SSO)  vsphere 5.5  release has several improvements, like the following: Completely re-written from the ground Multi-master architecture Native replication mechanism SSO now has site awareness (think

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