Advanced Lab environment - 05 Mass VD Port Group creation with PowerCLI

Published: 29 January 2023
on channel: Tech-Junkie
126
0

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****


Watch video Advanced Lab environment - 05 Mass VD Port Group creation with PowerCLI online, duration hours minute second in high quality that is uploaded to the channel Tech-Junkie 29 January 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 126 times and liked it 0 visitors.