VMware Cloud Community
burdweiser
Enthusiast
Enthusiast
Jump to solution

Create port groups from excel

I've got a spreadsheet with 60 port groups I need to create. My fields are VLAN and Name. Looking at the cmdlets reference guide it looks like the command to create one would be Get-VDSwitch -Name “Boston” | New-VDPortgroup -Name “Test SQL VLAN 250″  -VLanId 250 . Can someone help with the structure to create this from an excel file? I am checking the config maximums to see if I am going to hit a limit on my ports with vSphere 5.1 and need to set a certian number of ports per port group. Thanks.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$dvSw = Get-VDSwitch -Name "Boston"

Import-Csv dvPortgroups.csv -UseCulture | %{
 
New-VDPortgroup -Name $_.PgName -VlanId $_.VLanId -NumPorts $_.Ports -VDSwitch $dvSw
}

The CSV file is expected to have 3 columns

PgName,VLanId,Ports

pg1,100,32

pg2,100,32

You might want to check the number of available ports on the dvSwitch first, to check if you can add ll the requested ports for the portgroups


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

View solution in original post

2 Replies
ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi,

Assuming your input csv file looks like the following and creating one dvSwitch:

Name,VLAN

VLAN100,100

VLAN200,200

VLAN300,300

Try the following:

$data = Import-CSV C:\input.csv

foreach ($d in $data)

{

    Get-VDSwitch -Name "Boston" | New-VDPortgroup -Name $d.Name -VlanId $d.Name

}

Sample output:

Name                            NumPorts PortBinding                                                                                                                                                                                                                                                                          

----                                 --------       -----------                                                                                                                                                                                                                                                                           

VLAN100                       128          Static                                                                                                                                                                                                                                                                               

VLAN200                       128          Static                                                                                                                                                                                                                                                                               

VLAN300                       128          Static                               

Make sure you run the script with a right permission.

Hope this helps,

Steven.

LucD
Leadership
Leadership
Jump to solution

Try something like this

$dvSw = Get-VDSwitch -Name "Boston"

Import-Csv dvPortgroups.csv -UseCulture | %{
 
New-VDPortgroup -Name $_.PgName -VlanId $_.VLanId -NumPorts $_.Ports -VDSwitch $dvSw
}

The CSV file is expected to have 3 columns

PgName,VLanId,Ports

pg1,100,32

pg2,100,32

You might want to check the number of available ports on the dvSwitch first, to check if you can add ll the requested ports for the portgroups


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