Skip to content

Instantly share code, notes, and snippets.

@johnsmclay
Last active April 10, 2024 11:07
Show Gist options
  • Save johnsmclay/525fb3cbe7d93572612a606ea0001c13 to your computer and use it in GitHub Desktop.
Save johnsmclay/525fb3cbe7d93572612a606ea0001c13 to your computer and use it in GitHub Desktop.
How to get vLAN tagging support on windows 10, especially for Intel NICs
# Need to run this as Administrator
# To turn on Hyper-V if necessary, see:
# https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
Import-Module Hyper-V
# A hashtable of NIC/vLAN names and vLAN IDs you want to create NICs for
$vlans=@{ "Main" = 1;
"Public" = 2;
"Public 2" = 3;
"Phones" = 4;
"Guest" = 5;
"Non-Tech" = 6}
# Up to you. Not really used, just referenced in script.
$vswitch_name = "Virtual Switch"
# The physical ethernet adapter, can also be "Wi-Fi".
# Use "Get-NetAdapter" to get a full list if you have multiple ethernet or wifi adapters
$physnic = Get-NetAdapter -Name "Ethernet"
# The switch will bridge your virtual adapters and the physical adapter
New-VMSwitch -Name "$vswitch_name" -NetAdapterName $physnic.Name -AllowManagementOS $true -Notes 'Parent OS, VMs, Ethernet'
Foreach ($vlan in $vlans.GetEnumerator()) {
$vlanid = $vlan.Value
$vnic_name = $vlan.Name
# Create the virtual NIC
Add-VMNetworkAdapter -ManagementOS -Name "$vnic_name" -StaticMacAddress $physnic.MacAddress -SwitchName "$vswitch_name"
# Set the vLAN
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "$vnic_name" -Access -VlanID "$vlanid"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment