People,
I'm deploying multiple ESXi servers which needs to have access to lots of VLAN, hence I need to create about 10-15 VLANs as VM Port Group (Network Label) in one single ESXi host and as standard vSwitch.
This ESXi hosts does not have the capability of Distributed Switch, hence I must manually create the VLAN/Netowrk label one by one in standard vSwitch, and then move on to another ESXi hosts in all of the racks in the data center.
So I wonder if anyone here please can assist me in how to modify the script below to automate the VLAN creation in vSwitch2 from VLAN 1 up to 20 ?
Get-VirtualSwitch -Name vSwitch2 -VMHost PRODESXi01 |
New-VirtualPortgroup -Name "Company_Network_VLAN $($_.VLAN)" -VLANID $($_.VLAN)
Existing:
Name of the vSwitch: vSwitch2
VM Port Group Label: Company_Network_VLAN1
VLAN ID: 1
VM Port Group Label: Company_Network_VLAN2
VLAN ID: 2
....
....
VM Port Group Label: Company_Network_VLAN20
VLAN ID: 20
Thanks in advance.
Something like this ?
foreach($esx in Get-VMHost){
$sw = Get-VirtualSwitch -Name vSwitch2 -VMHost $esx
1..20 | %{
New-VirtualPortgroup -VirtualSwitch $sw -Name "Company_Network_VLAN $($_)" -VLANID $_
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this ?
foreach($esx in Get-VMHost){
$sw = Get-VirtualSwitch -Name vSwitch2 -VMHost $esx
1..20 | %{
New-VirtualPortgroup -VirtualSwitch $sw -Name "Company_Network_VLAN $($_)" -VLANID $_
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, if I have some VLAN number to be created that is non-sequential like 2,6,7,8,51,110,165,166,167,168,2200,3500,4000
Do I just modify the script:
foreach($esx in Get-VMHost){
$sw = Get-VirtualSwitch -Name vSwitch2 -VMHost $esx
2,6,7,8,51,110,165,166,167,168,2200,3500,4000 | %{
New-VirtualPortgroup -VirtualSwitch $sw -Name "Company_Network_VLAN $($_)" -VLANID $_
}
}
Yes, that should work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, yes it works 🙂
You are so amazing.