62 lines
2.2 KiB
PowerShell
62 lines
2.2 KiB
PowerShell
<#
|
|
Required parameter:
|
|
-SwitchName Name of the existing standard vSwitch where the port groups will be created.
|
|
|
|
Optional parameter:
|
|
-BaseVlanId Starting VLAN ID. Default is 100.
|
|
The script creates:
|
|
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
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$SwitchName,
|
|
|
|
[ValidateRange(1, 4087)]
|
|
[int]$BaseVlanId = 120
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$switch = Get-VirtualSwitch -Name $SwitchName -ErrorAction Stop
|
|
|
|
$portGroups = @(
|
|
@{ 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) {
|
|
$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)"
|
|
}
|