Add finished scripts for creating port groups

This commit is contained in:
2026-04-17 11:08:59 +02:00
parent f28b403e4b
commit ecf97ee93c
4 changed files with 134 additions and 26 deletions

View File

@@ -5,14 +5,14 @@ Required parameter:
Optional parameter:
-BaseVlanId Starting VLAN ID. Default is 100.
The script creates:
HQ-SERVER-Linux = BaseVlanId
HQ-DMZ-Linux = BaseVlanId + 1
HQ-CLIENT-Linux = BaseVlanId + 2
INET-HQ-Linux = BaseVlanId + 3
INET-BRANCH-Linux = BaseVlanId + 4
HOME-Linux = BaseVlanId + 5
BR-SERVER-Linux = BaseVlanId + 6
BR-CLIENT-Linux = BaseVlanId + 7
ES2025-LX-HQ-SERVER-Linux = BaseVlanId
ES2025-LX-HQ-DMZ-Linux = BaseVlanId + 1
ES2025-LX-HQ-CLIENT-Linux = BaseVlanId + 2
ES2025-LX-INET-HQ-Linux = BaseVlanId + 3
ES2025-LX-INET-BRANCH-Linux = BaseVlanId + 4
ES2025-LX-HOME-Linux = BaseVlanId + 5
ES2025-LX-BR-SERVER-Linux = BaseVlanId + 6
ES2025-LX-BR-CLIENT-Linux = BaseVlanId + 7
Example:
.\Create-PortGroups.ps1 -SwitchName vSwitch0
@@ -23,7 +23,7 @@ param(
[string]$SwitchName,
[ValidateRange(1, 4087)]
[int]$BaseVlanId = 100
[int]$BaseVlanId = 120
)
$ErrorActionPreference = 'Stop'
@@ -31,14 +31,14 @@ $ErrorActionPreference = 'Stop'
$switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop
$portGroups = @(
@{ Name = 'HQ-SERVER-Linux'; VlanId = $BaseVlanId },
@{ Name = 'HQ-DMZ-Linux'; VlanId = $BaseVlanId + 1 },
@{ Name = 'HQ-CLIENT-Linux'; VlanId = $BaseVlanId + 2 },
@{ Name = 'INET-HQ-Linux'; VlanId = $BaseVlanId + 3 },
@{ Name = 'INET-BRANCH-Linux'; VlanId = $BaseVlanId + 4 },
@{ Name = 'HOME-Linux'; VlanId = $BaseVlanId + 5 },
@{ Name = 'BR-SERVER-Linux'; VlanId = $BaseVlanId + 6 },
@{ Name = 'BR-CLIENT-Linux'; VlanId = $BaseVlanId + 7 }
@{ Name = 'ES2025-LX-HQ-SERVER-Linux'; VlanId = $BaseVlanId },
@{ Name = 'ES2025-LX-HQ-DMZ-Linux'; VlanId = $BaseVlanId + 1 },
@{ Name = 'ES2025-LX-HQ-CLIENT-Linux'; VlanId = $BaseVlanId + 2 },
@{ Name = 'ES2025-LX-INET-HQ-Linux'; VlanId = $BaseVlanId + 3 },
@{ Name = 'ES2025-LX-INET-BRANCH-Linux'; VlanId = $BaseVlanId + 4 },
@{ Name = 'ES2025-LX-HOME-Linux'; VlanId = $BaseVlanId + 5 },
@{ Name = 'ES2025-LX-BR-SERVER-Linux'; VlanId = $BaseVlanId + 6 },
@{ Name = 'ES2025-LX-BR-CLIENT-Linux'; VlanId = $BaseVlanId + 7 }
)
foreach ($portGroup in $portGroups) {

View File

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

View File

@@ -5,10 +5,9 @@ Required parameter:
Optional parameter:
-BaseVlanId Starting VLAN ID. Default is 100.
The script creates:
WAN-Linux = BaseVlanId
INT-Linux = BaseVlanId + 1
DMZ-Linux = BaseVlanId + 2
VPN-Linux = BaseVlanId + 3
WS2024-LX-WAN-Linux = BaseVlanId
WS2024-LX-INT-Linux = BaseVlanId + 1
WS2024-LX-DMZ-Linux = BaseVlanId + 2
Example:
.\Create-PortGroups.ps1 -SwitchName vSwitch0
@@ -18,7 +17,7 @@ param(
[Parameter(Mandatory = $true)]
[string]$SwitchName,
[ValidateRange(1, 4094)]
[ValidateRange(1, 4092)]
[int]$BaseVlanId = 100
)
@@ -27,10 +26,9 @@ $ErrorActionPreference = 'Stop'
$switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop
$portGroups = @(
@{ Name = 'WAN-Linux'; VlanId = $BaseVlanId },
@{ Name = 'INT-Linux'; VlanId = $BaseVlanId + 1 },
@{ Name = 'DMZ-Linux'; VlanId = $BaseVlanId + 2 },
@{ Name = 'VPN-Linux'; VlanId = $BaseVlanId + 3 }
@{ Name = 'WS2024-LX-WAN-Linux'; VlanId = $BaseVlanId },
@{ Name = 'WS2024-LX-INT-Linux'; VlanId = $BaseVlanId + 1 },
@{ Name = 'WS2024-LX-DMZ-Linux'; VlanId = $BaseVlanId + 2 }
)
foreach ($portGroup in $portGroups) {

View File

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