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.

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

SolusVM Easy Quick Install

Quick Easy Install Debian/Ubuntu apt update reboot wget https://files.soluslabs.com/install.shsh install.sh Centos yum update reboot wget https://files.soluslabs.com/install.shsh install.sh If you get an error it is because you need to install: wget Try a

vCloud user training

It is clear that a lot of vCloud users are not well trained by their vCloud providers. This is due to the fact that the current training available is for

PowerShell your world cup

PowerShell This is something that is very exciting and if you are interested you should try it. I found the post and tried it. Here is a function and how

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