fborges555
Enthusiast
Enthusiast

Bulk Standard port adding

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
7 Replies
Nawals
Expert
Expert

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.
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
fborges555
Enthusiast
Enthusiast

L.

When running your script  I get

"an empty pipe element is not allow"

Thanks

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
fborges555
Enthusiast
Enthusiast

L.

Right after the import-CSV

pastedImage_4.png

0 Kudos
fborges555
Enthusiast
Enthusiast

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

0 Kudos
fborges555
Enthusiast
Enthusiast

L.

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

Thanks a bunch

0 Kudos