As many of you have read in the release notes of vSphere PowerCLI 5.8 r1 we have introduced a new cmdlet ‘Get-OvfConfiguration’ along with a new parameter on the ‘Import-vApp’ cmdlet to allow users to specify and set the OVF properties for an OVF deployment.
In Part 1 we will dive in to the Get-OvfConfiguration cmdlet and how to add your configuration to the OvfConfiguration object.
in Part 2 will be on using the –OvfConfiguration parameter with the values from this post, to import vApps into your environment.
So, how does this work?
Let’s take a look at the cmdlet documentation. running ‘get-help get-OvfConfiguration’ will bring this back for us.
As you can see the syntax of the command requires the path to the OVF and either the vCenter server parameter or that you are already connected to a vCenter server. If your PowerCLI session is already connected, you do not need to add this parameter to the command.
First, we’ll connect to our vCenter server to return the OvfConfiguration properties.
Now, we can go ahead and run the ‘Get-OvfConfiguration’ cmdlet. We’ll specify the path to the OVF.
$ovfpath = “Path to OVA”
We can then use our $ovfpath variable in our command: Get-OvfConfiguration –Ovf $ovfpath
Now that we have the configuration properties of the OVA, lets take a look at them.
$ovfconfig.ToHashTable() | ft –autosize
We can now see the properties that we can assign values to for deployment. There are several ways we can do this. *Note: The actual position of the property in the OvfConfiguration object may be different from its OVF key.
Assigning Values to vApp Properties
The OvfConfiguration parameter accepts both the OvfConfiguration object as well as a plain Hash Table.
Populating Objects
Populating the object would be done in the following manner:
$ovfconfig.NetworkMapping.Network_1.Value = “Network 1”
$ovfconfig.IpAssignment.IpProtocol.Value = “IPv4”
$ovfconfig.vami.VMware_vCenter_Log_Insight.hostname.value = “SDDC-LogInsight”
$ovfconfig.vami.VMware_vCenter_Log_Insight.ip0.value = “10.144.99.70”
$ovfconfig.vami.VMware_vCenter_Log_Insight.netmask0.value = “255.255.255.0”
$ovfconfig.vami.VMware_vCenter_Log_Insight.gateway.value = “10.144.99.1”
$ovfconfig.vami.VMware_vCenter_Log_Insight.DNS.value = “10.144.99.5”
$ovfconfig.vm.rootpw.value = “VMware1!”
you can see the steps I took to add these values in the screenshots below.
Enter the ovfconfig variable and hit enter. you will see a number of objects.
To set the values for these properties we must find the key that we need to set. We can do this by going deeper into each object.
In this part we dive in to the vami properties. we can see that there are 5 properties we can set.
- hostname
- ip0
- netmask0
- gateway
- DNS
Following the pattern above we find the path of each key and set the values to each property.
After setting the vami properties, the last property to set is the root password.
A few other examples from Alan Renouf include specifying the network mapping for Standard and Distributed port groups
# Populate an OvfConfiguration object
# The populated OvfConfiguration object specifies a network mapping by standard port group.
$ovfConfig = Get-OvfConfiguration “myOvfTemplate.ovf”
$portGroup = Get-VirtualPortGroup -Name “Network 2” -Standard
$ovfConfig.NetworkMapping.Network.Value = $portGroup
Import-VApp $ovfPath -OvfConfiguration $ovfConfig -VMHost $vmHost
# Populate an OvfConfiguration object
# The populated OvfConfiguration object specifies a network mapping by distributed port group.
$ovfConfig = Get-OvfConfiguration “myOvfTemplate.ovf”
$vdPortGroup = Get-VDPortgroup “myDistributedPortGroup”
$ovfConfig.NetworkMapping.Network.Value = $vdPortGroup
Leveraging Hash Tables
We can also directly populate a HashTable to be used with the Import-vApp Cmdlet:
$ovfconfig = @{
“vami.gateway.VMware_vCenter_Log_Insight” = “10.144.99.1”
“vm.rootpw” = “VMware1!”
“vami.DNS.VMware_vCenter_Log_Insight” = “10.144.99.5”
“vami.ip0.VMware_vCenter_Log_Insight”= “10.144.99.70”
“vami.hostname.VMware_vCenter_Log_Insight” = “SDDC-LogInsight”
“vami.netmask0.VMware_vCenter_Log_Insight” = “255.255.255.0”}
which looks like this:
Either method will deliver the same results; it comes down to personal preference as to which way you do this.
Now that we have populated our OvfConfiguration object we can use it to import vApps.
Stay tuned for Part 2 on using the –OvfConfiguration parameter to import the vApps