VMware Cloud Community
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Add multiple PVLAN IDs to dvSwitch?

Hi Guys,

I have an existing dvSwitch with an existing Primary PVLAN, I would like to add multiple community vlans, I've tried a few scripts without much luck, any help is appreciated.

Nicholas
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The PowerCLI functions that you need are in Luc's blogpost. You can cut and paste them into your PowerCLI session or you can save them in a .ps1 file and load the file into your PowerCLI session by dot-sourcing the file. For example:

PowerCLI C:\> . .\dvSwitch.ps1

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
17 Replies
nicholas1982
Hot Shot
Hot Shot
Jump to solution

This is what I tried if it helps.

$dcName = "DC"

$dvSName = "DVS1"

$dvSw = Get-dvSwitch $dcName $dvSName

New-dvSwPVLAN $dvSw 900 902,903 "community","community"

Nicholas
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Ok I think, I may have the answer, I'm running PowerCLI 5.1 Release 1 which I think doesn't have the cmdlets, downloading release 2.

Nicholas
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Using the new PowerCLI 5.1 Release 2 VDS cmdlets you can do:

$dcName = "DC"

$dvSName = "DVS1"

$dvSW = Get-VDSwitch -Name $dvSName -Location $dcName

New-VDPortGroup -VDSwitch $dvSW -Name "Community vlan 900" -VlanId 900

New-VDPortGroup -VDSwitch $dvSW -Name "Community vlan 902" -VlanId 902

New-VDPortGroup -VDSwitch $dvSW -Name "Community vlan 903" -VlanId 903

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think you need the Get-VDSwitch cmdlet, not Get-dvSwitch.


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

nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks, but that create portgroups with standard vlans, I need to add PVLANS?

Nicholas
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks Luc, So I need to populate the DVswitch with the community Private VLAN then create port groups, do you have a simple script for this?

Nicholas
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Afaik the New-VDPortgroup cmdlet cannot yet be used to create private vlan's. You can revert to Luc's private vlan functions in his blog post:

dvSwitch scripting – Part 6 – Private VLAN | LucD notes


Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks, will i need to install additional cmdlets? If so do you know where I can get it?

Nicholas
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The PowerCLI functions that you need are in Luc's blogpost. You can cut and paste them into your PowerCLI session or you can save them in a .ps1 file and load the file into your PowerCLI session by dot-sourcing the file. For example:

PowerCLI C:\> . .\dvSwitch.ps1

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

I see... Do I need to change Get-dvSwitch to Get-VDSwitch ?

Nicholas
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The Get-dvSwitch function and Get-VDSwitch cmdlet return different type of objects. So you better use the Get-dvSwitch function.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Great, it works, I just used the whole script, I didn't realize the functions were needed at first.

Using the new cmdlets in Powercli 5.1 R2 is it possible to create multiple DV portgroups with specified number of ports?

Nicholas
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Its ok just worked it out New-VDPortgroup -VDSwitch "DLS1" -Name PG905 -NumPorts 1

Nicholas
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

I do have one other question, I'm trying to run the script that creates the PVLAN, but just so I can add additional secondary vlans, I get an error cause its tries to create the primary again. what would be the way to just add secondary vlans?

Nicholas
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Using Luc's functions I created a new function Set-dvSwPVLAN that you can use to add an additional secondary vlan.

function Set-dvSwPVLAN{
param($dvSw, $primaryNr, [int[]] $secondaryNr, [string[]] $secondaryType)

$spec = New-Object VMware.Vim.VMwareDVSConfigSpec

# Primary
$pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec

# Secondaries
for($i = 0;$i -lt $secondaryNr.Count; $i++){
  $pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec
  $pvlan.operation = "add"
  $pvlan.pvlanEntry = New-Object VMware.Vim.VMwareDVSPvlanMapEntry
  $pvlan.pvlanEntry.primaryVlanId = $primaryNr
  $pvlan.pvlanEntry.pvlanType = $secondaryType[$i].ToLower()
  $pvlan.pvlanEntry.secondaryVlanId = $secondaryNr[$i]
  $spec.PvlanConfigSpec += $pvlan
}

$dvSw.UpdateViewData()
$spec.ConfigVersion = $dvSw.Config.ConfigVersion
$taskMoRef = $dvSw.ReconfigureDvs_Task($spec)

$task = Get-View $taskMoRef
while("running","queued" -contains $task.Info.State){
  $task.UpdateViewData("Info")
}
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks, I'm not sure where im going wrong

function Get-dvSwitch{

  param($dcName,$dvSwName)

  $dcNetFolder = Get-View (Get-Datacenter $dcName | Get-View).NetworkFolder

  $found = $null

  foreach($net in $dcNetFolder.ChildEntity){

  if($net.Type -eq "VmwareDistributedVirtualSwitch"){

  $temp = Get-View $net

  if($temp.Name -eq $dvSwName){

  $found = $temp

  }

  }

  }

  $found

}

function New-dvSwPVLAN{

  param($dvSw, $primaryNr, [int[]] $secondaryNr, [string[]] $secondaryType)

  $spec = New-Object VMware.Vim.VMwareDVSConfigSpec

  # Primary

  $pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec

  $pvlan.operation = "add"

  $pvlan.pvlanEntry = New-Object VMware.Vim.VMwareDVSPvlanMapEntry

  $pvlan.pvlanEntry.primaryVlanId = $primaryNr

  $pvlan.pvlanEntry.pvlanType = "promiscuous"

  $pvlan.pvlanEntry.secondaryVlanId = $primaryNr

  $spec.PvlanConfigSpec += $pvlan

  # Secondaries

  for($i = 0;$i -lt $secondaryNr.Count; $i++){

  $pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec

  $pvlan.operation = "add"

  $pvlan.pvlanEntry = New-Object VMware.Vim.VMwareDVSPvlanMapEntry

  $pvlan.pvlanEntry.primaryVlanId = $primaryNr

  $pvlan.pvlanEntry.pvlanType = $secondaryType[$i].ToLower()

  $pvlan.pvlanEntry.secondaryVlanId = $secondaryNr[$i]

  $spec.PvlanConfigSpec += $pvlan

  }

  $dvSw.UpdateViewData()

  $spec.ConfigVersion = $dvSw.Config.ConfigVersion

  $taskMoRef = $dvSw.ReconfigureDvs_Task($spec)

  $task = Get-View $taskMoRef

  while("running","queued" -contains $task.Info.State){

  $task.UpdateViewData("Info")

  }

}

$datacenterName = "DC1"

$dvSwitchName = "VDS1"

$dvSw = Get-dvSwitch $datacenterName $dvSwitchName

New-dvSwPVLAN $dvSw 900 910 "community"

Nicholas
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Hey, its all good found the problem, i had it set to New-dvSwPVLAN rather than Set-dvSwPVLAN, Thanks again for all your help guys, really appreciate it. This will make it much easier for us to migrate to the vDS with PVLANS Smiley Happy

function Get-dvSwitch{

  param($dcName,$dvSwName)

  $dcNetFolder = Get-View (Get-Datacenter $dcName | Get-View).NetworkFolder

  $found = $null

  foreach($net in $dcNetFolder.ChildEntity){

  if($net.Type -eq "VmwareDistributedVirtualSwitch"){

  $temp = Get-View $net

  if($temp.Name -eq $dvSwName){

  $found = $temp

  }

  }

  }

  $found

}

function Set-dvSwPVLAN{

param($dvSw, $primaryNr, [int[]] $secondaryNr, [string[]] $secondaryType)

$spec = New-Object VMware.Vim.VMwareDVSConfigSpec

# Primary

$pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec

# Secondaries

for($i = 0;$i -lt $secondaryNr.Count; $i++){

  $pvlan = New-Object VMware.Vim.VMwareDVSPvlanConfigSpec

  $pvlan.operation = "add"

  $pvlan.pvlanEntry = New-Object VMware.Vim.VMwareDVSPvlanMapEntry

  $pvlan.pvlanEntry.primaryVlanId = $primaryNr

  $pvlan.pvlanEntry.pvlanType = $secondaryType[$i].ToLower()

  $pvlan.pvlanEntry.secondaryVlanId = $secondaryNr[$i]

  $spec.PvlanConfigSpec += $pvlan

}

$dvSw.UpdateViewData()

$spec.ConfigVersion = $dvSw.Config.ConfigVersion

$taskMoRef = $dvSw.ReconfigureDvs_Task($spec)

$task = Get-View $taskMoRef

while("running","queued" -contains $task.Info.State){

  $task.UpdateViewData("Info")

}

}

$datacenterName = "DC1"

$dvSwitchName = "DVS1"

$dvSw = Get-dvSwitch $datacenterName $dvSwitchName

Set-dvSwPVLAN $dvSw 900 918 "community"

Set-dvSwPVLAN $dvSw 900 916 "community"

Set-dvSwPVLAN $dvSw 900 920 "community"

Nicholas
0 Kudos