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

Submit a Comment

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