alepetit
Contributor
Contributor

Enable guestInfo.ovfEnv into virtual machine with powercli

Jump to solution

Hi all,

I Cannot action this option with powershell script. This option is a following "VMware Tools guestInfo.ovfEnv variable"

Screen options:

Capture d’écran 2017-10-29 à 12.10.57.png

Do you have an idea ?

Regards,

Alex.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Ok, the transport cna be set like this

$vmName  = 'MyVM'

$vm = Get-VM -Name $vmName

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.VAppConfig = New-Object VMware.Vim.VmConfigSpec

$spec.VAppConfig.OvfEnvironmentTransport = @('com.vmware.guestInfo')

$vm.ExtensionData.ReconfigVM($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership

If the OVF doesn't export that property (did you check with Get-Reconfiguration), you will have to set it after the appliance has been imported.

You could use the Set-AdvancedSetting cmdlet.

See for example Re: Script to check for existence and add advanced settings to VMs if necessary.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
alepetit
Contributor
Contributor

Hi LucD,

Thanks for your return.

I try this :

$vm = Get-VM -Name "template_ubuntu-1604-base"

Get-AdvancedSetting -Entity $vm  | select Name, Value | ft

But I dont have key guestInfo.ovfEnv.

Output:

checkpoint.vmstate                                                                                                                                                                               

ehci.pcislotnumber                                                                                34                                                                                             

ethernet0.bsdname                                                                                 en0                                                                                            

ethernet0.connectiontype                                                                          nat                                                                                            

ethernet0.displayname                                                                             Ethernet                                                                                       

ethernet0.linkstatepropagation.enable                                                             false                                                                                          

ethernet0.pcislotnumber                                                                           33                                                                                             

gui.fullscreenatpoweron                                                                           false                                                                                          

gui.viewmodeatpoweron                                                                             windowed                                                                                       

hgfs.linkrootshare                                                                                TRUE                                                                                           

hgfs.maprootshare                                                                                 TRUE                                                                                           

isolation.tools.hgfs.disable                                                                      false                                                                                          

msg.autoanswer                                                                                    true                                                                                           

nvram                                                                                             template_ubuntu-1604-base.nvram                                                                

pcibridge0.pcislotnumber                                                                          17                                                                                             

pcibridge0.present                                                                                TRUE                                                                                           

pcibridge4.functions                                                                              8                                                                                              

pcibridge4.pcislotnumber                                                                          21                                                                                             

pcibridge4.present                                                                                TRUE                                                                                           

pcibridge4.virtualdev                                                                             pcieRootPort                                                                                   

pcibridge5.functions                                                                              8                                                                                              

pcibridge5.pcislotnumber                                                                          22                                                                                             

pcibridge5.present                                                                                TRUE                                                                                           

pcibridge5.virtualdev                                                                             pcieRootPort                                                                                   

pcibridge6.functions                                                                              8                                                                                              

pcibridge6.pcislotnumber                                                                          23                                                                                             

pcibridge6.present                                                                                TRUE                                                                                           

pcibridge6.virtualdev                                                                             pcieRootPort                                                                                   

pcibridge7.functions                                                                              8                                                                                              

pcibridge7.pcislotnumber                                                                          24                                                                                             

pcibridge7.present                                                                                TRUE                                                                                           

pcibridge7.virtualdev                                                                             pcieRootPort                                                                                   

proxyapps.publishtohost                                                                           false                                                                                          

remotedisplay.vnc.enabled                                                                         FALSE                                                                                          

remotedisplay.vnc.password                                                                        KMaLyPxB                                                                                       

remotedisplay.vnc.port                                                                            5900                                                                                           

replay.filename                                                                                                                                                                                  

replay.supported                                                                                  false                                                                                          

scsi0.pcislotnumber                                                                               16                                                                                             

scsi0:0.redo                                                                                                                                                                                     

usb.pcislotnumber                                                                                 32                                                                                             

uuid.action                                                                                       create                                                                                         

virtualhw.productcompatibility                                                                    hosted                                                                                         

vmci0.pcislotnumber                                                                               35                                                                                             

vmotion.checkpointfbsize                                                                          65536000                                                                                       

vmware.tools.internalversion                                                                      2147483647                                                                                     

vmware.tools.requiredversion                                                                      10277                                                                                          

migrate.hostLogState                                                                              none                                                                                           

migrate.migrationId                                                                               0                                                                                              

migrate.hostLog                                                                                   ./template_ubuntu-1604-base-724c57d9.hlog                                                      

guestinfo                                                                                         whatever                                                                                       

Regards,

A.

0 Kudos
LucD
Leadership
Leadership

Not all the settings are in there by default, that is why you would need to set it with Set-AdvancedSetting


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
alepetit
Contributor
Contributor

Hi LucD,

Thanks first.

I try this test:

$vm = Get-VM -Name "template_ubuntu-1604-base"

New-AdvancedSetting -Name "guestInfo.ovfEnv" -Value $true -Entity $vm -Confirm:$false

After, I call vmtoolsd into vm server. example:

root@HcxpQzpsCe:~# vmtoolsd --cmd "info-get guestinfo.ovfenv"

Output value is : True

I dont want this. I want enable guestInfo.ovfEnv with the same target than GUI checkbox.

A output value follow example :

<?xml version="1.0" encoding="UTF-8"?>

<Environment

     xmlns="http://schemas.dmtf.org/ovf/environment/1"

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xmlns:oe="http://schemas.dmtf.org/ovf/environment/1"

     xmlns:ve="http://www.vmware.com/schema/ovfenv"

     oe:id=""

     ve:vCenterId="vm-101">

   <PlatformSection>

      <Kind>VMware ESXi</Kind>

      <Version>6.5.0</Version>

      <Vendor>VMware, Inc.</Vendor>

      <Locale>en</Locale>

   </PlatformSection>

   <PropertySection>

         <Property oe:key="key001" oe:value="value001"/>

   </PropertySection>

   <ve:EthernetAdapterSection>

      <ve:Adapter ve:mac="00:50:56:a1:34:22" ve:network="CT-LAB-SRV" ve:unitNumber="7"/>

   </ve:EthernetAdapterSection>

</Environment>

Regards,

Alexandre.

0 Kudos
LucD
Leadership
Leadership

You shouldn't set it to true, but provide the OvfEntry object.

William explains that in  An alternate way to inject OVF properties when deploying virtual appliances directly onto ESXi

And a sample setOvfEnv.ps1 script


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
alepetit
Contributor
Contributor

I Know the script setOvfEnv.ps1 but I want setup a templateVm and not a VM.

My idea is,

- Enabling VirtualMachineConfigSpec and send keys and defaults values.

$vm = Get-VM -Name "template_ubuntu-1604-base"

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.vAppConfig = New-Object VMware.Vim.VmConfigSpec

$spec.vAppConfig.property = New-Object VMware.Vim.VAppPropertySpec[] (20)

$spec.vAppConfig.property[0] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[0].operation = "add"

$spec.vAppConfig.property[0].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[0].info.key = 3

$spec.vAppConfig.property[0].info.classId = "PropertyClassID_3"

$spec.vAppConfig.property[0].info.instanceId = "PropertyInstanceID_3"

$spec.vAppConfig.property[0].info.id = "Property_3"

$spec.vAppConfig.property[0].info.category = "PropertyCategory_3"

$spec.vAppConfig.property[0].info.label = "Property_3"

$spec.vAppConfig.property[0].info.type = "string"

$spec.vAppConfig.property[0].info.userConfigurable = $true

$spec.vAppConfig.property[0].info.defaultValue = "PropertyDefaultValue_3"

$spec.vAppConfig.property[0].info.value = ""

$spec.vAppConfig.property[0].info.description = "PropertyDescription_3"

$vm.ExtensionData.ReconfigVM_Task($spec)

- Enabling param guestInfo.ovfEnv

- convert my VM to template.

$vm | Set-VM -ToTemplate -Name "template_ubuntu-1604-base_001" 

Example:

https://www.virtuallyghetto.com/2012/06/ovf-runtime-environment.html or http://www.thevirtualist.org/creating-customizable-linux-ovf-template/

0 Kudos
LucD
Leadership
Leadership

Ok, the transport cna be set like this

$vmName  = 'MyVM'

$vm = Get-VM -Name $vmName

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.VAppConfig = New-Object VMware.Vim.VmConfigSpec

$spec.VAppConfig.OvfEnvironmentTransport = @('com.vmware.guestInfo')

$vm.ExtensionData.ReconfigVM($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
alepetit
Contributor
Contributor

Thanks you LucD !

My first script:

# RETRIEVE VM

$vm = Get-VM -Name $vmName

# Init VirtualMachineConfigSpec object

$vm = Get-VM -Name "template_ubuntu-1604-base"

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.vAppConfig = New-Object VMware.Vim.VmConfigSpec

$spec.vAppConfig.property = New-Object VMware.Vim.VAppPropertySpec[] (20)

# DNS

$spec.vAppConfig.property[1] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[1].operation = "add"

$spec.vAppConfig.property[1].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[1].info.key = 1

$spec.vAppConfig.property[1].info.id = "dns0"

$spec.vAppConfig.property[1].info.value = "8.8.8.8"

# GATEWAY

$spec.vAppConfig.property[2] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[2].operation = "add"

$spec.vAppConfig.property[2].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[2].info.key = 2

$spec.vAppConfig.property[2].info.id = "gateway"

$spec.vAppConfig.property[2].info.value = ""

# HOSTNAME

$spec.vAppConfig.property[3] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[3].operation = "add"

$spec.vAppConfig.property[3].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[3].info.key = 3

$spec.vAppConfig.property[3].info.id = "hostname"

$spec.vAppConfig.property[3].info.value = "server001"

# IPADDRESS

$spec.vAppConfig.property[4] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[4].operation = "add"

$spec.vAppConfig.property[4].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[4].info.key = 4

$spec.vAppConfig.property[4].info.id = "ip0"

$spec.vAppConfig.property[4].info.value = "server001"

# STATIC IP (TRUE/FALSE)

$spec.vAppConfig.property[5] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[5].operation = "add"

$spec.vAppConfig.property[5].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[5].info.key = 5

$spec.vAppConfig.property[5].info.id = "ip_static"

$spec.vAppConfig.property[5].info.value = $true

# NETMASK

$spec.vAppConfig.property[6] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[6].operation = "add"

$spec.vAppConfig.property[6].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[6].info.key = 6

$spec.vAppConfig.property[6].info.id = "netmask0"

$spec.vAppConfig.property[6].info.value = ""

# PASSWORD

$spec.vAppConfig.property[7] = New-Object VMware.Vim.VAppPropertySpec

$spec.vAppConfig.property[7].operation = "add"

$spec.vAppConfig.property[7].info = New-Object VMware.Vim.VAppPropertyInfo

$spec.vAppConfig.property[7].info.key = 7

$spec.vAppConfig.property[7].info.id = "password"

$spec.vAppConfig.property[7].info.value = ""

# Enable guestInfo

$spec.VAppConfig.OvfEnvironmentTransport = @('com.vmware.guestInfo')

# Reconfigure VM

$vm.ExtensionData.ReconfigVM_Task($spec)

# Convert to template

$vm | Set-VM -ToTemplate -Name $vmname

0 Kudos