WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • Apple
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 // 5 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.

$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

  • PowerCLI 13.0 on Photon OS
  • Heads Up - Unable to open VIB archive in streaming mode using Export-EsxImageProfile with PowerCLI 13.0
  • How to install PowerCLI 13.0 and use new Image Builder & Auto Deploy cmdlets on Apple Silicon?
  • Creating custom ESXi images using vSphere Lifecycle Manager (vLCM) UI and PowerCLI cmdlets for vSphere 8
  • Automated enablement of vSphere with Tanzu using vSphere Zones in vSphere 8

Categories // Automation, PowerCLI, vSphere, vSphere Web Client Tags // ovf, PowerCLI

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.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

      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
  4. Mohsen Pahlevanzadeh says

    02/07/2022 at 5:30 am

    William, How can I do it for local system and file-base?

    Reply

Thanks for the comment! Cancel reply

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

Search

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

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

Recent

  • ESXi configstorecli enhancement in vSphere 8.0 Update 1 03/28/2023
  • ESXi on Intel NUC 13 Pro (Arena Canyon) 03/27/2023
  • Quick Tip - Enabling ESXi Coredumps to be stored on USB 03/26/2023
  • How to disable the Efficiency Cores (E-cores) on an Intel NUC? 03/24/2023
  • Changing the default HTTP(s) Reverse Proxy Ports on ESXi 8.0 03/22/2023

Advertisment

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

Copyright WilliamLam.com © 2023

 

Loading Comments...