VMware Cloud Community
gertvangorp
Enthusiast
Enthusiast
Jump to solution

get-ovfconfigurationa and multiple networkmappings

Hi all,

I am trying to import multiple OVA's in to a VMC on AWS environment.  These OVA.s sometimes have multiple vNIC's connected.  with the get-ovfconfigueration cmdlet

I can see all the old networkmappings. 

PS C:\Windows\system32> $ovfPath = "\my.ova"

PS C:\Windows\system32> $ovfConfig = Get-OvfConfiguration -Ovf $ovfPath

PS C:\Windows\system32> $ovfconfig

====================================

OvfConfiguration: my.ova

   Properties:

   -----------

   NetworkMapping

PS C:\Windows\system32> $ovfconfig.NetworkMapping

Portgroup1 Portgroup2

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

Is there an easy way to change all the networkmappings (I do not know the content of the networkmapping upfront )  to a same (NSX-T) portgroup?

thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Looks like I misread the structure of the object.

Try like this

$pgName = 'xyz'

$ovfPath = "\my.ova"

$ovfConfig = Get-OvfConfiguration -Ovf $ovfPath

$ovfconfig.NetworkMapping | Get-Member -MemberType CodeProperty |

ForEach-Object -Process {

   $ovfConfig.NetworkMapping."$($_.Name)".Value = $pgName

}


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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Would this work?

It assumes that all networks point to the same portgroup 'xyz'

$pgName = 'xyz'

$ovfPath = "\my.ova"

$ovfConfig = Get-OvfConfiguration -Ovf $ovfPath

$ovfconfig.NetworkMapping |

ForEach-Object -Process {

   $netName = ($_ | Get-Member -MemberType CodeProperty).Name

   $ovfConfig.NetworkMapping."$netName".Value = $pgName

}


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

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

thanks again for the quick response

tried to code but get this error

Get-Member : You must specify an object for the Get-Member cmdlet.

At line:3 char:21

+    $netName = ($_ | Get-Member -MemberType CodeProperty).Name

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

    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException

    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand

The property 'Value' cannot be found on this object. Verify that the property exists and can be set.

At line:5 char:4

+    $ovfConfig.NetworkMapping."$netName".Value = $pgName

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

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

Hi,

when I put everything on 1 line

$ovfconfig.NetworkMapping |ForEach-Object -Process {$netName = ($_ | Get-Member -MemberType CodeProperty).Name ;$ovfConfig.NetworkMapping."$netName".Value = $pgName}

I get this error

The property 'Value' cannot be found on this object. Verify that the property exists and can be set.

At line:1 char:113

+ ... Property).Name ;$ovfConfig.NetworkMapping."$netName".Value = $pgName}

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

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you check what this shows?

$ovfconfig.NetworkMapping | Get-Member


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

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

PS C:\Windows\system32> $ovfconfig.NetworkMapping | Get-Member

   TypeName: System.Object

Name           MemberType   Definition

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

Externalvlan   CodeProperty VMware.VimAutomation.Sdk.Util10Ps.ObjectCustomization.SimpleExtensionProperty

master0002dvlp CodeProperty VMware.VimAutomation.Sdk.Util10Ps.ObjectCustomization.SimpleExtensionProperty

Equals         Method       bool Equals(System.Object obj)

GetHashCode    Method       int GetHashCode()

GetType        Method       type GetType()

ToString       Method       string ToString()

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

PS C:\Windows\system32> $ovfconfig.NetworkMapping.Portgroup1 | get-member

   TypeName: VMware.VimAutomation.ViCore.Impl.V1.Ovf.OvfPropertyImpl

Name               MemberType Definition

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

Equals             Method     bool Equals(System.Object obj)

GetHashCode        Method     int GetHashCode()

GetPropertyPath    Method     string GetPropertyPath(), string OvfProperty.GetPropertyPath()

GetType            Method     type GetType()

ToString           Method     string ToString()

DefaultValue       Property   System.Object DefaultValue {get;}

Description        Property   string Description {get;}

Key                Property   string Key {get;}

OvfTypeDescription Property   string OvfTypeDescription {get;}

Value              Property   System.Object Value {get;set;}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like I misread the structure of the object.

Try like this

$pgName = 'xyz'

$ovfPath = "\my.ova"

$ovfConfig = Get-OvfConfiguration -Ovf $ovfPath

$ovfconfig.NetworkMapping | Get-Member -MemberType CodeProperty |

ForEach-Object -Process {

   $ovfConfig.NetworkMapping."$($_.Name)".Value = $pgName

}


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

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

A BIG POWERSHELL GURU like you  can also have a moment of weakness . 🙂

THANKS A LOT

looks like a still need to learn a lot 🙂

Gert

0 Kudos
gertvangorp
Enthusiast
Enthusiast
Jump to solution

Hi,

I also have some VMs that where exported out of a VMC on AWS environment with a NSX-T envirnment.

needed to change some stuff in the command

$ovfconfig.NetworkMapping.nsx |

Get-Member -MemberType CodeProperty |

ForEach-Object -Process { $ovfConfig.NetworkMapping.nsx."$($_.Name)".Value = $pgName }

Greetings

Gert

0 Kudos