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.

[box]Connect-VIServer {vCenter-FQDN}[/box]

Supply a username and password.

Now remove any snapshots from the VM;

[box]Get-Snapshot Test-VM | Remove-Snapshot -confirm:$false[/box]

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

[box]Get-VM -Name Test-VM | Shutdown-VMGuest -confirm:$false[/box]

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;

[box]Get-VM -Name Test-VM | Get-CDDrive | Set-CDDrive -NoMedia -confirm:$false[/box]

Finally we export our VM;

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

Related Articles, References, Credits, or External Links

NA

6 thoughts on “VMware: Export a VM to OVA With PowerCLI

  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.

  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?

  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.

Leave a Reply

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