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

@@ -1,53 +0,0 @@
<#
Required parameter:
-SwitchName Name of the existing standard vSwitch where the port groups will be created.
Optional parameter:
-BaseVlanId Starting VLAN ID. Default is 120.
The script creates:
ES2025-WIN-INET = BaseVlanId
ES2025-WIN-CPH-INT = BaseVlanId + 1
ES2025-WIN-CPH-DEV = BaseVlanId + 2
ES2025-WIN-AAL-INT = BaseVlanId + 3
Example:
.\Create-PortGroups.ps1 -SwitchName vSwitch0
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$SwitchName,
[ValidateRange(1, 4091)]
[int]$BaseVlanId = 130
)
$ErrorActionPreference = 'Stop'
$switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop
$portGroups = @(
@{ Name = 'ES2025-WIN-INET'; VlanId = $BaseVlanId },
@{ Name = 'ES2025-WIN-CPH-INT'; VlanId = $BaseVlanId + 1 },
@{ Name = 'ES2025-WIN-CPH-DEV'; VlanId = $BaseVlanId + 2 },
@{ Name = 'ES2025-WIN-AAL-INT'; VlanId = $BaseVlanId + 3 }
)
foreach ($portGroup in $portGroups) {
$existing = Get-VirtualPortGroup -VirtualSwitch $switch -Name $portGroup.Name -ErrorAction SilentlyContinue
if ($existing) {
if ($existing.VLanId -ne $portGroup.VlanId) {
Set-VirtualPortGroup -VirtualPortGroup $existing -VLanId $portGroup.VlanId | Out-Null
Write-Host "Updated $($portGroup.Name) VLAN to $($portGroup.VlanId)"
}
else {
Write-Host "$($portGroup.Name) already exists"
}
continue
}
New-VirtualPortGroup -VirtualSwitch $switch -Name $portGroup.Name -VLanId $portGroup.VlanId | Out-Null
Write-Host "Created $($portGroup.Name) with VLAN $($portGroup.VlanId)"
}