PowerCLI

 View Only
  • 1.  Bulk Standard port adding

    Posted Mar 19, 2020 07:09 PM

    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

    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



  • 2.  RE: Bulk Standard port adding

    Posted Mar 19, 2020 07:14 PM


  • 3.  RE: Bulk Standard port adding
    Best Answer

    Posted Mar 19, 2020 07:16 PM

    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'

    }



  • 4.  RE: Bulk Standard port adding

    Posted Mar 20, 2020 07:20 PM

    L.

    When running your script  I get

    "an empty pipe element is not allow"

    Thanks



  • 5.  RE: Bulk Standard port adding

    Posted Mar 20, 2020 07:23 PM

    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?



  • 6.  RE: Bulk Standard port adding

    Posted Mar 20, 2020 11:48 PM

    L.

    Right after the import-CSV



  • 7.  RE: Bulk Standard port adding

    Posted Mar 21, 2020 01:10 AM

    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



  • 8.  RE: Bulk Standard port adding

    Posted Mar 21, 2020 02:11 AM

    L.

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

    Thanks a bunch