Automation

 View Only
  • 1.  Create port groups from excel

    Posted Sep 08, 2013 10:48 PM

    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.



  • 2.  RE: Create port groups from excel

    Posted Sep 09, 2013 01:21 AM

    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.



  • 3.  RE: Create port groups from excel
    Best Answer

    Posted Sep 09, 2013 05:48 AM

    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