<# Creates PG-VLAN port groups on a vSwitch. Required parameter: -SwitchName Name of the existing standard vSwitch. Example: .\Create-PortGroups.ps1 -SwitchName vSwitch0 #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$SwitchName ) $ErrorActionPreference = 'Stop' $portGroups = @( @{ Name = 'PG-VLAN10'; VlanId = 10 }, @{ Name = 'PG-VLAN11'; VlanId = 11 }, @{ Name = 'PG-VLAN12'; VlanId = 12 }, @{ Name = 'PG-VLAN20'; VlanId = 20 }, @{ Name = 'PG-VLAN21'; VlanId = 21 }, @{ Name = 'PG-VLAN23'; VlanId = 23 }, @{ Name = 'PG-VLAN30'; VlanId = 30 }, @{ Name = 'PG-VLAN51'; VlanId = 51 }, @{ Name = 'PG-VLAN114'; VlanId = 114 }, @{ Name = 'PG-VLAN211'; VlanId = 211 }, @{ Name = 'PG-VLAN1130'; VlanId = 1130 }, @{ Name = 'PG-VLAN1138'; VlanId = 1138 } ) $switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop foreach ($pg in $portGroups) { $existing = Get-VirtualPortGroup -VirtualSwitch $switch -Name $pg.Name -ErrorAction SilentlyContinue if ($existing) { Write-Host "$($pg.Name) already exists" continue } New-VirtualPortGroup -VirtualSwitch $switch -Name $pg.Name -VLanId $pg.VlanId | Out-Null Write-Host "Created $($pg.Name) with VLAN $($pg.VlanId)" }