• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

virtuallyGhetto

  • About
  • Privacy
  • VMware Cloud
  • Home Lab
  • Nested Virtualization
  • Automation
    • VMware Kickstart
    • VMware API/SDK/CLI
    • VMware vMA/VIMA
    • VMware OVF / OVFTOOL
  • Apple Mac
  • VCSA
  • VSAN
You are here: Home / Automation / Updating OVF properties for a VM using vSphere API and PowerCLI 

Updating OVF properties for a VM using vSphere API and PowerCLI 

10/31/2017 by William Lam 4 Comments

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$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.

More from my site

  • Automated Lab Deployment Script for vSphere with Tanzu using NSX Advanced Load Balancer (NSX ALB)
  • Quick Tip – How to retrieve deleted VM history?
  • Which VM was this vSphere VM cloned from?
  • How to build a customizable Raspberry Pi OS Virtual Appliance (OVA)?
  • Automating HAProxy VM deployment with 3-NIC configuration using PowerCLI
Share this...
  • Twitter
  • Facebook
  • Linkedin
  • Reddit
  • Pinterest

Filed Under: Automation, PowerCLI, vSphere, vSphere Web Client Tagged With: ovf, PowerCLI

Reader Interactions

Comments

  1. Frank says

    11/03/2017 at 5:09 am

    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.

    Reply
    • William Lam says

      11/03/2017 at 6:05 am

      See https://www.virtuallyghetto.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

      Reply
  2. Frank says

    11/03/2017 at 12:08 pm

    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.

    Reply
  3. Morgan Yang says

    07/06/2018 at 10:07 am

    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

    Reply

Thanks for the comment! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Services Business Unit (CSBU) at VMware. He focuses on Automation, Integration and Operation for the VMware Cloud Software Defined Datacenters (SDDC)

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Sponsors

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy