VMware: Export a VM to OVA With PowerCLI

KB ID 0001507

Problem

It’s pretty easy to create an OVA/OVF from the vCenter Web console, but what about from Powershell / PowerCLI? Below I run though converting a 2008 x32 Windows server to OVA.

Solution

I’ll leave the web console in the background so you can see whats happening. From PowerCLI the first task is to connect to the vCenter.

Connect-VIServer {vCenter-FQDN}

Supply a username and password.

PowerCLI Connect to vCenter

Now remove any snapshots from the VM;

Get-Snapshot Test-VM | Remove-Snapshot -confirm:$false

PowerCLI Remove Snapshots

The VM needs to be off before we can export it, the following command will shut it down gracefully;

Get-VM -Name Test-VM | Shutdown-VMGuest -confirm:$false

PowerCLI Shutdown VM

If your VM has an ISO connected to it, it can have an annoying habit of adding that to the OVA file! So remove any presented .iso files with the following command;

Get-VM -Name Test-VM | Get-CDDrive | Set-CDDrive -NoMedia -confirm:$false

PowerCLI Disconnect ISO from VM

Finally we export our VM;

Get-VM -Name Test-VM | Export-VApp -Destination ‘E:\Exported‘ -Format OVA

PowerCLI Export VM to OVA

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

6 Comments

  1. Hi Pete,
    Thanks for the instruction for exporting to OVA with PowerCLI. I am reasonably new to PowerCLI and can see the benefits. Just some reason, the syntax “Export-VApp” will error:

    Export-VApp : 13/05/2020 9:15:01 AM Export-VApp Current license or ESXi version prohibits execution of the requested operation.
    At line:1 char:51
    + … iance_v1200_dhcp_1″ | Export-VApp -Destination “C:\Utils” -Format OVA
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Export-VApp], RestrictedVersion
    + FullyQualifiedErrorId : Client20_VappServiceImpl_ExportVApp_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.ExportVApp

    I am running ESXi 607; do you have any idea what the issue is?, thank you.

    Post a Reply
    • Yes, you are using FREE ESX that does not support all the storage APIs sorry.

      Post a Reply
  2. Thank you for this article, In it the vm’s get powered off to do the conversion but is there a way to have them power back on once the vmware is completed doing the ova? I know it is easy to power the vm’s on with cli but how do you check if ova completed before powering on?

    Post a Reply
  3. Capture the output of the Export-VApp, like this:

    $ovfExport = Export-VApp

    Then you can access the State property to see if it is running like so…

    if ($ovfExport.State -ne “Running”) {
    Start-VM -vm
    }

    The if will only trigger when the Export-VApp is Done or the State is Error. How you check errors is a different conversation though.

    Post a Reply
  4. Thank you! Very clear and working case.

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *