54 lines
1.7 KiB
PowerShell
54 lines
1.7 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 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)"
|
|
}
|