Automation

 View Only
  • 1.  Adding multiple port groups to same distributed switch

    Posted Jan 31, 2022 07:59 PM

    I'm seeing a bunch of scripts to create new vlans, and add them to a distributed switch.

    We currently have a bunch of existing vlans needing to be added to the same distributed switch, in a ESX 7.0 environment.

    Ideally, I'd like to be able to import a list of vlans and add them to the distributed switch.

    All help is greatly appreciated



  • 2.  RE: Adding multiple port groups to same distributed switch

    Posted Jan 31, 2022 08:13 PM

    You could take one of the scripts you found and run it in a foreach loop.

    The loop can circle through all the input data (for example rows in a CSV).



  • 3.  RE: Adding multiple port groups to same distributed switch
    Best Answer

    Posted Jan 31, 2022 10:02 PM

    For example, if you have the data in a CSV like this

    Name,VLANId
    Test1,100
    Test2,101

    you could do something like this

    $dvSwName = 'vdSw1'
    
    $dvs = Get-VDSwitch -Name $dvSwName
    
    Import-Csv -Path .\portgroup.csv -UseCulture -PipelineVariable row |
    ForEach-Object -Process {
      New-VDPortgroup -VDSwitch $dvs -Name $row.Name -VlanId $row.VLANId -Confirm:$false
    }


  • 4.  RE: Adding multiple port groups to same distributed switch

    Posted Feb 08, 2022 05:11 PM

    Thank you