Quantcast
Channel: VMware Communities : Popular Discussions - vCloud Director PowerCLI
Viewing all articles
Browse latest Browse all 13334

PowerCLI error vCloud Director assigning Org vDC/vApp network to VM

$
0
0

Hello,

I'm working on a script that imports VMs from vCenter into vCloud Director by creating vApps within an Organization's vDC then assigning a network to the VM. The script reads in a lost of VMs, vApp names, Networks, etc. from a CSV file. The network I'm assigning to the VM inside the vApp already exists within the Org vDC's list of Networks. One part of the script adds the specified Org vDC network to the vApp - which works fine. However, when assigning that network to the VM itself, I get this error:

Set-CINetworkAdapter : 01-Aug-18 08:53:10       Set-CINetworkAdapter            The specified parameter 'VAppNetwork' expects a single

value, but your name criteria 'Network v2' corresponds to multiple values.

At C:\ps\scripts\testassignnetwork.ps1:10 char:99

+ ... rkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddres ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-CINetworkAdapter], VimExc

   eption

    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.Clo

   ud.Commands.Cmdlets.SetCINetworkAdapter

 

 

Set-CINetworkAdapter : 01-Aug-18 08:53:10       Set-CINetworkAdapter            CIVAppNetwork parameter: Could not find any of the

objects specified by name.

At C:\ps\scripts\testassignnetwork.ps1:10 char:99

+ ... rkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddres ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...ork VAppNetwork:RuntimePropertyInfo) [Set-CINetworkAd

   apter], ObnRecordProcessingFailedException

    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.Cloud.

   Commands.Cmdlets.SetCINetworkAdapter

 

Here's where I add the existing Org vDC network to the vApp:

Write-Host "`nImporting Org vDC network(s) in the new vApps"

Import-Csv $ImportPath | Foreach-Object {

New-CIVAppNetwork -ParentOrgVdcNetwork (Get-OrgVdc $_.NewOrgvDC | Get-OrgVdcNetwork $_.NewNetwork) -VApp (Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName) -Direct -RunAsync

}

Write-Host -ForegroundColor Green "Done"

Which works perfectly (the CSV file lists two VMs, both going to separate vApps):

Importing Org vDC network(s) in the new vApps

 

Name                           State      % Complete Start Time   Finish Time

----                           -----      ---------- ----------   -----------

vdcUpdateVappNetworkSection    Queued              0 08:52:05 AM

vdcUpdateVappNetworkSection    Queued              0 08:52:10 AM

Done

 

Now I try to assign the VM inside the vApp to the network I just added to the vApp:

Write-Host "`nAssigning vApp networks to the VMs"

Import-Csv $ImportPath | Foreach-Object {

#Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName | Get-CIVM $_.vAppName | Get-CINetworkAdapter | where{$_.MacAddress -eq $_.MAC} | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddressAllocationMode Pool -Connected $true

Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName | Get-CIVM $_.vAppName | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddressAllocationMode Pool -Connected $true

}

Write-Host -ForegroundColor Green "Done"

 

Which results in the error I pasted above (I get both errors twice since the CSV file has two entries). Any idea what's going on? I'd appreciate the help. Thanks.


Viewing all articles
Browse latest Browse all 13334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>