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.
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
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"
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.
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
I think you need the Get-VDSwitch cmdlet, not Get-dvSwitch.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, but that create portgroups with standard vlans, I need to add PVLANS?
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?
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
Thanks, will i need to install additional cmdlets? If so do you know where I can get it?
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
I see... Do I need to change Get-dvSwitch to Get-VDSwitch ?
The Get-dvSwitch function and Get-VDSwitch cmdlet return different type of objects. So you better use the Get-dvSwitch function.
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?
Its ok just worked it out New-VDPortgroup -VDSwitch "DLS1" -Name PG905 -NumPorts 1
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?
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")
}
}
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"
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
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"