Install PowerCLI and use script to create lots of VD port groups.
Run below commands in elevated powershell
Set-ExecutionPolicy RemoteSigned
Install-Module -Name VMware.PowerCLI
answer "y" and "a"
Do or Don't participate the improvement program
Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCeip $False -Confirm:$False
Get dSwitch and port groups
Get-VDSwitch
Get-VDPortgroup
Create a "Test" portgroup with 8 ports, vlan id 202 under dSwitch "SimpleLab_dSwitch01"
New-VDPortgroup -Name "Test" -NumPorts 8 -VlanId 202 -VDSwitch "SimpleLab_dSwitch01"
First couple lines of DistributedSwitch.csv
VDSwitch,Site,VlanID
SimpleLab_dSwitch01,00TransitNetwork,201
SimpleLab_DSwitch01,00TransitNetwork,202
SimpleLab_DSwitch01,01Primary,1001
The script: CreateVDPortGroup.ps1
****CreateVDPortGroup.ps1 begin****
$VDPortGroupCsv = Import-Csv .\DistributedSwitch.csv
Disconnect-VIServer -confirm:$false
$Prefix = "SimpleLab_"
$count = 1
$vc = "vc01.simplelab.int"
Connect-VIServer -Server $vc
Foreach ($VDPortGroup in $VDPortGroupCsv) {
$PortGroupName = "$Prefix" + "$($VDPortGroup.Site)_" + "Vlan" + $("{0:d4}" -f $VDPortGroup.VlanId)
"Loopcount $count start"
"Createing $PortGroupName"
if ( -not $(Get-VDPortgroup $PortGroupName -ErrorAction SilentlyContinue) ) {
"$PortGroupName not Found"
New-VDPortgroup -Name "$PortGroupName" -NumPorts 8 -VLanId "$($VDPortGroup.VlanId)" -VDSwitch "$($VDPortGroup.VDSwitch)"
}
else {
"$PortGroupName Found"
}
"Finished handling $PortGroupName"
"Loopcount $count end"
""
$count++
sleep 1
}
****CreateVDPortGroup.ps1 end****