VMware offers a virtual machine format called OVF that can be saved to and loaded from an XML file. This article covers how to import and export your VMX files in the most efficient way possible with PowerShell
The “vmware powercli” is a command-line tool that allows users to import and export an OVF file in VMware with PowerShell.
I’m often asked about utilizing PowerCLI to do a variety of activities in a vCenter cluster at my present position. In this article, I’ll explain how I learnt to import an OVF file into VMware.
OVF File
This is the tale of a recent request for help from a coworker who wanted to transfer a custom monitoring appliance template to a newly created vCenter cluster. My colleague was working on a tight deadline and didn’t have access to the template.
Install the PowerCLI module using Install-Module -Name PowerCLI if you haven’t previously.
Connecting to the vCenter server
Never one to pass up an opportunity to utilize PowerShell or PowerCLI, I stepped right in to assist. I got the information I needed from my colleague and started connecting to the cluster:
PS6> Connect-VIServer -Server vcenter.mydomain.local -Credential (Get-Credential)
It just takes a few moments to finish this. You’ll need to know what verbs to employ after you’ve linked. You may accomplish this using the PowerCLI cmdlet Get-Command -Module.
Two cmdlets in particular stand out:
These two cmdlets seem to be precisely what you’re looking for. But first, since this is a learning exercise for both me and you, I’ll brush up on the appropriate use of each.
Exporting Virtual Machines to an OVF File
If you don’t provide a location, the Export-VApp cmdlet will export the powered down VM as an OVF to the current directory your session is in.
I already have a route in mind, so I’ll use the C:Exported-OVF directory, but your results may differ. Knowing this, you can use Export-VApp to export the VM template to the specified folder.
PS6> Export-VApp -VM ‘My_VM_Template’ -Destination ‘C:Exported-OVF’
However, there is a problem. An OVF cannot be created from a running VM. There’s no need to be concerned; this is a simple repair. Modify your code a bit further and make sure you use the Shutdown-VMGuest cmdlet to shut down the VM first.
PS6> Shutdown-VMGuest -VM ‘My_VM_Template’
Rerun the Export-VApp cmdlet you tried previously now that the template appliance is offline. This procedure will take a few minutes, and the appliance was not very huge to begin with.
When you’re done, you should have a ready-to-deploy appliance in another vCenter environment. Or maybe you don’t.
Using OVF Files to Import
A file should now be present on your local file system. It is acceptable to import it. You’ll need to query the datastore to import it into, as well as the VM host, to do so. You can then utilize both objects to import it using the Import-Vapp cmdlet.
PS6> $myDatastore = Get-Datastore -Name “MyDatastore1” PS6> $vmHost = Get-VMHost -Name “MyHost” PS6> $vmHost | Import-vApp -Source ‘C:Exported-OVFMy_VM_TemplateMy_VM_Template.ovf’ -Datastore $myDatastore -Force
But hold on! This isn’t going to work. This failed in my case since I didn’t realize I was connected to a different vCenter cluster.
When I started importing the previously exported VM appliance, something strange occurred. There were a slew of red error notices.
The server is not a member of a vCenter cluster, hence it lacks the required license to finish the import using PowerCLI, according to the error notice. This is a VMware-imposed restriction.
No problem, I was still able to login to the host’s web interface and manually import using the HTML5 interface. Give the imported appliance a name, choose the OVF, datastore, deployment type (thick or thin provisioned), and test the settings using the wizard. After that, pick Finish to begin the import.
While the prior import effort would have worked well with a vCenter cluster, it would not have worked in this case. This took a bit longer than anticipated, but it was simple. More information regarding the procedure may be found here.
The import was successful in the end, and my colleague made their deadline.
Summary
I had no idea before this exercise that not all PowerCLI cmdlets were accessible in every case. However, we both gained a new skill and, despite facing some unexpected hardship, we were able to complete the work at hand.
We frequently hurry through IT initiatives in search of a ‘quick’ cure. Watch your pace, take a minute or two to ask questions, and take a step back to grasp the issue you’re attempting to solve. You could discover that you’ve learned something new.
The “powercli import ova” is a PowerShell script that allows users to import and export an OVF file in VMware. The process of importing and exporting an OVF file can be tedious, but the powercli script makes it much easier.
Frequently Asked Questions
Related Tags
- how to create an ova file in vmware
- vmware import ovf and vmdk
- open ova file in vmware
- vmware cmdlets powershell
- vmware-api powershell