VMware Cloud Community
cloudtrainer
Contributor
Contributor

Import-vApp is failing with Duplicate Element 'AddressOnParent'

HI,

I am trying to deploy an OVA file using powershell script. I found a script from internet and modified it a little bit and execute. During execution at Import-VApp command i am seeing this error: Import-VApp Line 157: Duplicate element 'AddressOnParent'.

I am able to deploy the OVA manually. But thru powershell script, i am seeing this error. Any help would be appreciated.

Please find my powershell script below.

    param(

  )

  trap {

  #  "`nError Information`n=================`nCategory: {0}`nID: {2}`nType: {1}#`nMessage: {3}" -f

  #  $_.CategoryInfo.Category, $_.Exception.GetType().FullName,

  #  $_.FullyQualifiedErrorID, $_.Exception.Message

  #  $_.ErrorDetails

  #  $_

   $_.Exception.Message

   $LASTEXITCODE = 0

   $ERROR.clear()

   exit 9027

  }

  $ErrorActionPreference = "Stop"

  #---- Custom values ::> START <:: ----- #

  $vCenterServer = "10.52.213.156"

  $vCenterPort = "443"

  $vCenterProtocol ="https"

  $vCenterUsername = "administrator"

  $vCenterPassword = "Passw0rd!"

  $vAppName = "VCS821-V1"

  $resourcePool =   "RP-1"

  $dstore =  "Collab-Storage"

  $dsCluster="Yes"

  $PortProfile = "VLAN 98"

  $vAPPPropertyId_ip4enable = "IPv4 Enable"

  $vAPP_ip4enable = "True"

  $vAPPPropertyId_ip4address = "IPv4 Address"

  $vAPP_ip4address = "10.51.98.20"

  $vAPPPropertyId_ip4netmask = "IPv4 Netmask"

  $vAPP_ip4netmask = "255.255.255.0"

  $vAPPPropertyId_ip4gateway = "Ipv4 Gateway"

  $vAPP_ip4gateway = "10.51.98.1"

  $vAPPPropertyId_ip6enable = "Ipv6 Enable"

  $vAPP_ip6enable = "False"

  #$vAPPPropertyId_ip6address = "IPv6 Address"

  #$vAPP_ip6address = ""

  #$vAPPPropertyId_ip6gateway = "IPv6 Gateway"

  #$vAPP_ip6gateway = ""

  $vAPP_defaultRouteKey = 1

  $vAPP_defaultRouteCmd = ""

  #---- Custom values  ::> END <:: ----- #

  Add-PSSnapin VMware.VimAutomation.Core

  Connect-VIServer -Server $vCenterServer -Port $vCenterPort -Protocol $vCenterProtocol -User $vCenterUsername -Password $vCenterPassword -WarningAction SilentlyContinue | Out-Null

  try{

  Write-Host " Start... "

  function Get-InventoryPath {

  param ($Object)

  $foldermark = 0

  $Path = $Object.Name

  #---

  Write-Host " Path = : $Path"

  #---

  do {

   if ( $Object.Id -cmatch "(Folder|Resources)" ) {

  $Parent = (Get-Folder $Object).parent

   }

   else {

  $Parent = (Get-View  $Object).parent

  #---

  Write-Host " Parent = $Parent"

  #---

  if ( $Parent -cmatch "(Folder|ResourcePool)" ) {

   $foldermark = 1

  }

  elseif ( $foldermark ) {

   # a non-folder just to the left of a folder:

   # remove the folder off the start of the path

   # this will also remove the Datacenters/

   $Path = ( $Path.split( '/', 2 ) )[-1]

   $foldermark = 0

  }

   }

   if ($Parent -ne $null) {

  if ($Parent.Id -cmatch "Folder") {

   $Path = (Get-Folder $Parent).Name + "/" + $Path

  }

  else {

   $Path = (Get-View $Parent).Name + "/" + $Path

  }

  $Object = $Parent

   }

  } while ($Parent -ne $null)

  Write-Output $Path

   }

  $rp = Get-ResourcePool -name $resourcePool

  Write-Host " Resoure Pool = $rp"

  $cluster = $rp.ExtensionData.Owner

  $vhost = (Get-Cluster -Id $cluster).ExtensionData.Host[0]

  Write-Host " VHost = $vhost "

  $VMHost = Get-VMHost -Id $vhost

  Write-Host " VMHost = $VMHost "

  if ($PortProfile -ne "")

  {$PortgroupId = Get-VirtualPortGroup -Name $PortProfile -Distributed -VMHost (Get-VMHost $VMHost)}

  Write-host "PortGroup = $PortgroupId"

  if ($dsCluster -eq "Yes")

  {

  Write-Host "DS Cluster = YES"

  #$ds = Get-DatastoreCluster -id $dstore

  $ds = Get-DatastoreCluster -Name $dstore

  Write-Host "DS = $ds"            

  }

  else

  {

  $ds = Get-Datastore -id $dstore

  }

  Write-Host "Importing VApp .... "

  $ovalocation = "C:\Script\s42700x8_1_1_a2.ova"

  Write-Host "vAppName = $vAppName"

  $vms = Import-VApp -Source $ovalocation -Name $vAppName   -VMHost $VMHost #-Location $rp -Datastore $ds

  #$vms = Import-VApp -Source $ovalocation -Name $vAppName -Location $rp  -VMHost $VMHost -Datastore $ds

  $vapp = Get-VM -Name $vAppName

  $prop_ip4enable = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip4enable}

  $prop_ip4address = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip4address}

  $prop_ip4netmask = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip4netmask}

  $prop_ip4gateway = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip4gateway}

  $prop_ip6enable = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip6enable}

  #$prop_ip6address = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip6address}

  #$prop_ip6gateway = $vapp.ExtensionData.Config.VAppConfig.Property | where {$_.Id -eq $vAPPPropertyId_ip6gateway}

  # *****************************************

  $vm = Get-VM $vAppName

  $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

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

  $newProp = New-Object VMware.Vim.VAppPropertySpec

  $info = New-Object VMware.Vim.VirtualMachineConfigInfo

  $newProp.Operation = "edit"

  # ********************************************

  $newProp.Info = $prop_ip4enable

  $newProp.Info.Value = $vAPP_ip4enable

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  $newProp.Info = $prop_ip4address

  $newProp.Info.Value = $vAPP_ip4address

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  $newProp.Info = $prop_ip4netmask

  $newProp.Info.Value = $vAPP_ip4netmask

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  $newProp.Info = $prop_ip4gateway

  $newProp.Info.Value = $vAPP_ip4gateway

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  $newProp.Info = $prop_ip6enable

  $newProp.Info.Value = $vAPP_ip6enable

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  Write-Host "Custom Properties are set... "

  <#

  $newProp.Info = $prop_ip6address

  $newProp.Info.Value = $vAPP_ip6address

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  $newProp.Info = $prop_ip6gateway

  $newProp.Info.Value = $vAPP_ip6gateway

  $spec.VAppConfig.Property += $newProp

  $vm.ExtensionData.ReconfigVM($spec)

  #>

  #**********************************************

  $spec1 = New-Object VMware.Vim.VirtualMachineConfigSpec

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

  $spec1.vAppConfig.property = New-Object VMware.Vim.VAppPropertySpec[] (1)

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

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

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

  $spec1.vAppConfig.property[0].info.key = $vAPP_defaultRouteKey

  $spec1.vAppConfig.property[0].info.classId = "myClassID"

  $spec1.vAppConfig.property[0].info.instanceId = "1"

  $spec1.vAppConfig.property[0].info.id = "ios-config"

  $spec1.vAppConfig.property[0].info.category = "3. Additional Configuration Properties"

  $spec1.vAppConfig.property[0].info.label = "default-route"

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

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

  $spec1.vAppConfig.property[0].info.defaultValue = $vAPP_defaultRouteCmd

  $spec1.vAppConfig.property[0].info.value = $vAPP_defaultRouteCmd

  $spec1.vAppConfig.property[0].info.description = "Default route for management"

  #>

  $nores = $vm.ExtensionData.ReconfigVM_Task($spec1)

  Write-Output '<results>'

  if ( $vm ) {

  Write-Output '<row>'

  [System.String]::Concat('    <UniqueName>',$vm.Id,'</UniqueName>')

  [System.String]::Concat('    <VMName>',$vm.Name,'</VMName>')

  [System.String]::Concat('    <Moref>',$vm.Id,'</Moref>')

  [System.String]::Concat('<VMFullPath>',( Get-InventoryPath $vm ),'</VMFullPath>')

  [System.String]::Concat('<PGFullPath>',$PortgroupId.Id,'</PGFullPath>')

  Write-Output '</row>'

  }

  Write-Output '</results>'

  }

  finally {

   disconnect-VIServer -Confirm:$false

  }

Output looks like this:

PS C:\Users\Administrator> C:\Script\OvaTestFile2.ps1
Start...
Resoure Pool = RP-1
VHost = HostSystem-host-136
VMHost = 10.52.213.130
PortGroup = VLAN 98
DS Cluster = YES
DS = Collab-Storage
Importing VApp ....
vAppName = VCS821-V1
9/22/2014 3:23:58 AM Import-VApp Line 157: Duplicate element 'AddressOnParent'.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Is this perhaps an older OVA file ?

Which OVA package are you using for the tests ?


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

0 Kudos
cloudtrainer
Contributor
Contributor

Hi LucD,

The ova package name is "s42700x8_1_1_a2.ova". Its Cisco Telepresence Video Communications Server. I tried with the latest OVA also "s42700x8_2_1.ova". Still getting the same error.

Regards,

Kiran

0 Kudos
LucD
Leadership
Leadership

Did you have a look at the OVF file ?

You can extract the OVF file from the OVA package with most of the archiving softwares.

Or use the OVF Tool.


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

0 Kudos
alanrenouf
VMware Employee
VMware Employee

Did you try the new 5.8 R1 release with Get-OVFConfiguration which would simplify this code somewhat?  Not saying you wont get the same error but just wondered if you had tried it.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos