VMware Cloud Community
ga2peio
Contributor
Contributor
Jump to solution

Adding multiple port groups to same distributed switch

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

Labels (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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
}


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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
}


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

ga2peio
Contributor
Contributor
Jump to solution

Thank you

Reply
0 Kudos