VMware Cloud Community
sandui
Contributor
Contributor

PowerCLI vCloud director Org VDC network change for multiple vApp

Hello,

 

I am trying to assign/change and org VDC network with another one. The network is connected to multiple vApp. I am trying to use below script.

 I am getting the error when i am running this script for 2 or more vApp. When it's for only one vApp where the OrgNetwork is connected the script running well.

------------------------------------------------Used Script-------------------------------------------------------------------------------

$VApp1 = Get-CIVApp -Name 'Test'
$VApp2 = Get-CIVApp -Name 'Test_1'
$myVappNetwork2 = Get-CIVAppNetwork -Name 'Test_NSX_A'
$myVappNetwork3 = Get-CIVAppNetwork -Name 'Test_NSX_B'


foreach ($cldvm in $VApp1 )
{
$cldvm | Get-CIVAppNetwork -Name 'test_downlink_NSX-V_to_PG' | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork2
$cldvm | Get-CIVAppNetwork -Name 'test_downlink_NSX-V_to_PG_4001' | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork3
break
}


foreach ($plm in $VApp2) {
$plmm | Get-CIVAppNetwork -Name 'test_downlink_NSX-V_to_PG' | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork2

$plmm | Get-CIVAppNetwork -Name 'test_downlink_NSX-V_to_PG_400' | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork3

break
}

------------------------------------------------------ERROR---------------------------------------------------------------------------------

 

Set-CINetworkAdapter : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Cloud.Types.V1.CIVAppNetwork' required by parameter 'VAppNetwork'.
Specified method is not supported.
At C:\Users\isandu.TOCM-TEST.000\Desktop\vCloud_Automation\Test_Vapp_2.ps1:14 char:125
+ ... -CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork2
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CINetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.Cloud.Commands.Cmdlets.SetCINetworkAdapter

Set-CINetworkAdapter : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Cloud.Types.V1.CIVAppNetwork' required by parameter 'VAppNetwork'.
Specified method is not supported.
At C:\Users\isandu.TOCM-TEST.000\Desktop\vCloud_Automation\Test_Vapp_2.ps1:15 char:130
+ ... -CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork3
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CINetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.Cloud.Commands.Cmdlets.SetCINetworkAdapter

Set-CINetworkAdapter : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Cloud.Types.V1.CIVAppNetwork' required by parameter 'VAppNetwork'.
Specified method is not supported.
At C:\Users\isandu.TOCM-TEST.000\Desktop\vCloud_Automation\Test_Vapp_2.ps1:21 char:125
+ ... -CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork2
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CINetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.Cloud.Commands.Cmdlets.SetCINetworkAdapter

Set-CINetworkAdapter : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Cloud.Types.V1.CIVAppNetwork' required by parameter 'VAppNetwork'.
Specified method is not supported.
At C:\Users\isandu.TOCM-TEST.000\Desktop\vCloud_Automation\Test_Vapp_2.ps1:23 char:129
+ ... -CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $myVappNetwork3
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CINetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.Cloud.Commands.Cmdlets.SetCINetworkAdapter

0 Kudos
3 Replies
Macleud
Enthusiast
Enthusiast

Hello, Sandui.
Tell me a little more.
Do you want to add VDC network to a specific Vapp?

0 Kudos
sandui
Contributor
Contributor

Hello Macleud,

 

The networks are presented in OVDC also presented on each targeted vApp.

My goal is to swap/change a network presented in the vApp  and connected to the VMs belonging to this vApp with new network created and presented on the same vApp.

 

Example:

Org VDC Test_1:

Org VDC networks:

                   Test_A

                   Test_B

vApp_Test_1:

                   VM_Test_1------------Connected---------------Test_A

vApp_Test_2:

                   VM_Test_2-----------Connected----------------Test_A

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In the end I want the script to :

vApp_Test_1:

                   VM_Test_1------------Connected---------------Test_B

vApp_Test_2:

                   VM_Test_2-----------Connected----------------Test_B

 
 
Tags (1)
0 Kudos
Macleud
Enthusiast
Enthusiast

Hi, Sandui.

What version of vCloud? Do you use nsx-v or nsx-t?

0 Kudos