VMware: Export a VM to OVA With PowerCLI

OVA KB ID 0001507

Problem : Creating OVA files

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 Windows server to OVA.

Note: Update 25/03/25 – Had a friend try and do this today, the VM was very large (over 12Tb) it proceeded to create the conversion in the servers c:\windows\temp directory. Obviously, this is not good! If you encounter this, then change the system variables for %TEMP% and %TMP% to the drive/partition you watn to send the OVA to (Warning: this required a reboot to take effect).

Solution: Powershell > OVA

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

Connect-VIServer {vCenter-FQDN}

Supply a username and password.

PowerShell connect to to vCenter OVA

Now remove any snapshots from the VM;

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

Remove Snapshots with Powershell OVA

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

Powershell shut down VM OVA

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

remove CD drive form VM Powershell

Finally we export our VM.

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

Powershell Export VM to OVA

Related Articles, References, Credits, or External Links

Export VM to a Local Folder

Export-vApp-Command

VMware vSphere – How to Import and Export OVF and OVA Files

VMware: ISO Upload or Deploy OVA Fails ‘Undetermined Reason’

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 *