Deploying a new OVA/OVF containing OVF properties that need to be configured is super easy using PowerCLI's Get-OvfConfiguration and Import-VApp cmdlets. Many examples can be found online including the PowerCLI Deployment Github repository.
However, once an OVA/OVF has been deployed and running as a standard Virtual Machine, I found there were no out of the box cmdlets for manipulating the OVF properties for a VM as shown in the screenshot below.
Online searches also did not yield any results and hence the opopournity and article 🙂
Just like any VM reconfiguration, you will need to use the vSphere API ReconfigVM_Task() and to update various OVF settings for a VM, you will need to pass in VAppConfigSpec along with a VAppPropertySpec containing the individual OVF property values to update.
To demonstrate the use of this vSphere API, I have created a sample PowerCLI script called VMOvfProperty.ps1 which contains both a Get and Set function.
Here is an example of calling the Get-VMOvfProperty function which simply accepts a VM object (returned by Get-VM) and outputs the OVF property ID, Label, current value and Description as shown in the screenshot below.
If we now want to update some of these OVF properties, we can use the Set-VMOvfProperty which also accepts a VM object along with a hashtable that contains the OVF property IDs and their respective values to update. Below is an example on how to build the PowerShell hashtable based on the output provided above.
$VMNetwork = "sddc-cgw-network-1" $VMDatastore = "WorkloadDatastore" $VMNetmask = "255.255.255.0" $VMGateway = "192.168.1.1" $VMDNS = "192.168.1.254" $VMNTP = "50.116.52.97" $VMPassword = "VMware1!" $VMDomain = "vmware.local" $VMIPAddress = "192.168.1.10" $VMSyslog = "192.168.1.10" $ovfPropertyChanges = @{ "guestinfo.syslog"=$VMSyslog "guestinfo.domain"=$VMDomain "guestinfo.gateway"=$VMGateway "guestinfo.ntp"=$VMNTP "guestinfo.password"=$VMPassword "guestinfo.hostname"=$VMIPAddress "guestinfo.dns"=$VMDNS "guestinfo.ipaddress"=$VMIPAddress "guestinfo.netmask"=$VMNetmask }
We now simply feed our $ovfPropertyChanges hashtable along with the VM object to our Set-VMOvfProperty function as shown in the screenshot below.
If we now refresh our vSphere Web Client, we can see the OVF properties have been updated with the expected values.
You can also use the Get-VMOvfProperty function to confirm the changes.
Frank says
How do I do something like this to just an ESXi host? All these require a vCenter. What if I need to deploy a VM that is not a vCenter (VCSA) to a standalone host. The VM will be used to deploy the rest of my SDDC stack.
William Lam says
See https://www.williamlam.com/2014/05/how-to-finally-inject-ovf-properties-into-vcsa-when-deploying-directly-onto-esxi.html as ESXi does not support OVF properties natively
Frank says
Thanks, I think i was using --allowextraconfig and --allowallextraconfig after the host told me after it saw the additional properties. I even opened a GSS case and they could not help me. I'll give this a go.
Morgan Yang says
Thanks for writing this module, I have found it very helpful. However, I keep on getting an error message with "Wait-Task" on line 70
Updating OVF Properties ...
Wait-Task : Operation is not valid due to the current state of the object.
At /home/morgany/Documents/vmware/powershell/VMOvfProperty.ps1:70 char:14
+ $task1 | Wait-Task
+ ~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Wait-Task], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask
All the VM's were powered off when I run Set-VMOvfProperty, so I'm not sure why the error is occurring.
What's interesting is when I comment out "Wait-Task", Set-VMOvfProperty seems to run fine. I'm running on VSphere 6.0.0 Update 3
Mohsen Pahlevanzadeh says
William, How can I do it for local system and file-base?