I have a large number of new port groups that I want to create on an existing vSphere Distributed Switch. They will mostly have the same settings with only a few differences. How can I automate this with PowerCLI? I'd like to specify the name of an existing distributed switch, then have the script list the port groups that I'm going to add.
Thanks!
You can have multiple columns in a CSV, so that is not really a problem.
If you make your CSV something like this
Name,UplinkPorts,Vlan
pg1,32,12
pg2,64,14
pg3,64,2001
You can pass those values in the script like this
$vds = Get-VDSwitch -Name MyVDS
Import-Csv C:\portgroup-names.csv | %{
New-VDPortgroup -VDSwitch $vds -Name $_.Name -NumPorts $_.UplinkPorts -VlanId $_.Vlan
}
For the other 2 properties, description and uplinknames, you have to set these in another way.
For these you will need to use one of the SDK methods.
In fact the UplinkNames are set on the dvSwitch, not on the dvPortgroup afaik. Unless you mean something else ?
I'll get back to you for those 2 missing properties.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the distributed switch cmdlets new to PowerCLI 5.1 Release 2:
New-DistributedSwitchPortGroup -Name vDS01-VLAN22 -DistributedSwitch vDS01 -VLAN 22
How will you be providing the portgroup names ? In a CSV file ?
If yes, you could do something like
$vds = Get-VDSwitch -Name MyVDS
Import-Csv C:\portgroup-names.csv | %{
New-VDPortgroup -VDSwitch $vds -Name $_.Name -NumPorts 32
}
This assumes that your CSV looks like
Name
pg1
pg2
pg3
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Actually, I probably won't have enough to require a CSV file, but I do need to specify the following 5 fields for each port group:
-Name of Port Group
-Description of Port Group
-names of active uplinks
-Number of ports to use for the port group
-vlan ID to assign to the port group
I could use a CSV file, but how would I specifiy those 5 attributes for each port group?
(Thanks again Luc for your input, and Robert)
You can have multiple columns in a CSV, so that is not really a problem.
If you make your CSV something like this
Name,UplinkPorts,Vlan
pg1,32,12
pg2,64,14
pg3,64,2001
You can pass those values in the script like this
$vds = Get-VDSwitch -Name MyVDS
Import-Csv C:\portgroup-names.csv | %{
New-VDPortgroup -VDSwitch $vds -Name $_.Name -NumPorts $_.UplinkPorts -VlanId $_.Vlan
}
For the other 2 properties, description and uplinknames, you have to set these in another way.
For these you will need to use one of the SDK methods.
In fact the UplinkNames are set on the dvSwitch, not on the dvPortgroup afaik. Unless you mean something else ?
I'll get back to you for those 2 missing properties.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is a better explanation of what I’m thinking. For example, lets say I want to have 5 fields in my csv file, in the following order, that create a port group called “mgt-pg1”.
So I want a CSV file that has a line for this port group, something like:
Mgt-pg1, “Management Port Group Number 1”, {dvUplink1,dvUplink2}, 64, 220
Then I want to be able to use these 5 settings to define my port group using PowerCLI.
Thanks again