VMware Cloud Community
fborges555
Enthusiast
Enthusiast
Jump to solution

Bulk Standard port adding

Hi all.

I have an esxi host 6.0.0 that I need to add a bunch of port/Vlan to it but they are a bunch , has any gone through the steps of adding this using PSCLI

pastedImage_0.png

Instead of adding one by one import a text file

Netowrk label             VLAN ID

xxx.xxx.xxx.xxx                 01

xxx.xxx.xxx.xxx                 02

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, you want to add a number of Portgroups?

That is quite straightforward.

Does the switch already exist?

From your screenshot it looks as if this is a VSS.

Correct?

In that case you could do something like this

$esxName = 'MyEsx'

$vssName = 'vSwitch1'


$esx = Get-VMHost -Name $esxName

$vss = Get-VirtualSwitch -Name $vssName -VMHost $esx


Import-Csv -Path .\pg.csv |

ForEach-Object -Process {

    New-VirtualPortGroup -VirtualSwitch $vss -Name $_.'Network Label' -VLanId $_.'VLAN ID'

}


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

View solution in original post

Reply
0 Kudos
7 Replies
Nawals
Expert
Expert
Jump to solution

You can use my blog for this.PowerCLi Script to Automate to configure vSwitch, add Uplink and bulk virtual port groups

NKS Please Mark Helpful/correct if my answer resolve your query.
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, you want to add a number of Portgroups?

That is quite straightforward.

Does the switch already exist?

From your screenshot it looks as if this is a VSS.

Correct?

In that case you could do something like this

$esxName = 'MyEsx'

$vssName = 'vSwitch1'


$esx = Get-VMHost -Name $esxName

$vss = Get-VirtualSwitch -Name $vssName -VMHost $esx


Import-Csv -Path .\pg.csv |

ForEach-Object -Process {

    New-VirtualPortGroup -VirtualSwitch $vss -Name $_.'Network Label' -VLanId $_.'VLAN ID'

}


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

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

L.

When running your script  I get

"an empty pipe element is not allow"

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

On which line?
Can you show the complete error message?

There is only 1 pipeline in that code, it's on the Import-Csv.

Did you copy the pipeline symbol (|) at the end of that line?


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

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

L.

Right after the import-CSV

pastedImage_4.png

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

L.

PG.CSV file = xxx.xxx.xxx.xxx,xx

I had it  working with no error by doing the following

Import-Csv -path .\pg.csv | Foreach-object {

But after it run NO portgroup is added to switch0 or host

Reply
0 Kudos
fborges555
Enthusiast
Enthusiast
Jump to solution

L.

as always thank for your help, I was missing my header on my CSV therefore the loop was failing.

Thanks a bunch

Reply
0 Kudos