Rework into a single script for creating port groups

This commit is contained in:
2026-04-17 23:25:07 +02:00
parent ecf97ee93c
commit 63fd768d6c
5 changed files with 45 additions and 222 deletions

View File

@@ -0,0 +1,45 @@
<#
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)"
}