Table of Contents

Microsoft - Hyper-V - PowerShell - Notes

Get VLAN usage

# The FQDN of the Hyper-V failover cluster (or Hyper-V host).
$strHVCluster = "hvcl001.domain.local"
 
Get-VMNetworkAdapterVlan -ComputerName $strHVCluster

Check specific VLAN usage

# The FQDN of the Hyper-V failover cluster (or Hyper-V host).
$strHVCluster = "hvcl001.domain.local"
 
# One or more comma-separated IDs
[array]$arrVlan = 110,26
 
# Get all network adapter VLANs from the Hyper-V Cluster that are in Access mode or where the mode is not Access/Untagged (e.g. Trunk).
Get-VMNetworkAdapterVlan -ComputerName $strHVCluster | `
Where-Object {($_.OperationMode -eq "Access" -And $arrVlan -contains $_.AccessVlanId) `
-Or ($_.OperationMode -ne "Access" -And $_.OperationMode -ne "Untagged")}

Set multiple VLANs on Hyper-V guest networkadapter

  1. Get a list of the MAC addresses of the virtual network adapters on the VM:
    $strHVHost = "Hyper-V6"
    $strVMName = "TEST_firewall"
     
    Get-VMNetworkAdapter -ComputerName $strHVHost -VMName $strVMName
  2. Set the adapter with MAC address 00112233AABB to tagged in VLAN 1-100 with native VLAN 1:
    $strHVHost = "Hyper-V6"
    $strVMName = "TEST_firewall"
     
    Get-VMNetworkAdapter -ComputerName $strHVHost -VMName $strVMName | `
    Where-Object {$_.MacAddress -eq "00112233AABB"} | `
    Set-VMNetworkAdapterVlan -Trunk -AllowedVlanIdList "1-100" -NativeVlanId 1
  3. Check with:
    $strHVHost = "Hyper-V6"
    $strVMName = "TEST_firewall"
     
    Get-VMNetworkAdapterVlan -ComputerName $strHVHost -VMName $strVMName

Source: netgate - PfSense + Hyper-V + VLANs