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,57 +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 200.
The script creates:
WS2024-WIN-Paris-Core = BaseVlanId
WS2024-WIN-Paris-Dist = BaseVlanId + 1
WS2024-WIN-Paris-Client = BaseVlanId + 2
WS2024-WIN-LA-Paris = BaseVlanId + 3
WS2024-WIN-LA-Lyon = BaseVlanId + 4
WS2024-WIN-Lyon-Remote = BaseVlanId + 5
Example:
.\Create-PortGroups.ps1 -SwitchName vSwitch0
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$SwitchName,
[ValidateRange(1, 4089)]
[int]$BaseVlanId = 110
)
$ErrorActionPreference = 'Stop'
$switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop
$portGroups = @(
@{ Name = 'WS2024-WIN-Paris-Core'; VlanId = $BaseVlanId },
@{ Name = 'WS2024-WIN-Paris-Dist'; VlanId = $BaseVlanId + 1 },
@{ Name = 'WS2024-WIN-Paris-Client'; VlanId = $BaseVlanId + 2 },
@{ Name = 'WS2024-WIN-LA-Paris'; VlanId = $BaseVlanId + 3 },
@{ Name = 'WS2024-WIN-LA-Lyon'; VlanId = $BaseVlanId + 4 },
@{ Name = 'WS2024-WIN-Lyon-Remote'; VlanId = $BaseVlanId + 5 }
)
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)"
}