Automation

 View Only
  • 1.  get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 10:28 AM

    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



  • 2.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 10:43 AM

    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

    }



  • 3.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 10:51 AM

    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



  • 4.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 10:57 AM

    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



  • 5.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 11:17 AM

    Can you check what this shows?

    $ovfconfig.NetworkMapping | Get-Member



  • 6.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 12:31 PM

    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()



  • 7.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 12:32 PM

    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;}



  • 8.  RE: get-ovfconfigurationa and multiple networkmappings
    Best Answer

    Posted Apr 03, 2019 01:16 PM

    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

    }



  • 9.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 03, 2019 01:26 PM

    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



  • 10.  RE: get-ovfconfigurationa and multiple networkmappings

    Posted Apr 04, 2019 12:07 PM

    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