forked from Azure/azure-container-networking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet-NetAdapterPriorityVLanTag.ps1
59 lines (49 loc) · 3.36 KB
/
Set-NetAdapterPriorityVLanTag.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This script will set the PriorityVLANTag registry key on a multitenant windows VM
# This is needed for VLAN tagging to be honored so that SWIFT packets flow out properly to the Azure Host
function Set-NetAdapterPriorityVLanTag
{
New-Variable -Name PriorityVLANTagIdentifier -Value "*PriorityVLANTag" -Option ReadOnly
New-Variable -Name MellanoxSearchString -Value "*Mellanox*" -Option ReadOnly
New-Variable -Name RegistryKeyPrefix -Value "HKLM:\System\CurrentControlSet\Control\Class\" -Option ReadOnly
Write-Host "Searching for a network adapter with '$MellanoxSearchString' in description"
$ethernetName = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like $MellanoxSearchString } | Select-Object -ExpandProperty Name
if ($ethernetName)
{
Write-Host "Network adapter found: '$ethernetName'"
$ethernetNameIfInProperty = Get-NetAdapterAdvancedProperty | Where-Object { $_.RegistryKeyword -like $PriorityVLANTagIdentifier -and $_.Name -eq $ethernetName } | Select-Object -ExpandProperty Name
Write-Host "Searching network adapter properties for '$PriorityVLANTagIdentifier'"
if ($ethernetNameIfInProperty)
{
Write-Host "Found '$PriorityVLANTagIdentifier' in adapter's advanced properties"
Set-NetAdapterAdvancedProperty -Name $ethernetName -RegistryKeyword $PriorityVLANTagIdentifier -RegistryValue 3
Write-Host "Successfully set Mellanox Network Adapter: '$ethernetName' with '$PriorityVLANTagIdentifier' property value as 3"
return;
}
Write-Host "Could not find '$PriorityVLANTagIdentifier' in adapter's advanced properties"
Write-Host "Proceeding in a different way"
Write-Host "Searching through CIM instances for Network devices with '$MellanoxSearchString' in the name"
$deviceID = Get-CimInstance -Namespace root/cimv2 -ClassName Win32_PNPEntity | Where-Object PNPClass -EQ "Net" | Where-Object { $_.Name -like $MellanoxSearchString } | Select-Object -ExpandProperty DeviceID
if ($deviceID)
{
Write-Host "Device ID found: '$deviceID'"
Write-Host "Getting Pnp Device properites for '$deviceID'"
$registryKeySuffix = Get-PnpDeviceProperty -InstanceId $deviceID | Where-Object KeyName -EQ "DEVPKEY_Device_Driver" | Select-Object -ExpandProperty Data
Write-Host "Registry key suffix found: '$registryKeySuffix'"
$registryKeyFullPath = $RegistryKeyPrefix + $registryKeySuffix
Write-Host "Registry key full path: '$registryKeyFullPath'"
Write-Host "Updating '$PriorityVLANTagIdentifier' to be 3"
New-ItemProperty -Path $registryKeyFullPath -Name $PriorityVLANTagIdentifier -Value 3 -PropertyType String -Force
Write-Host "Updated successfully"
Write-Host "Restarting Mellanox network adapter for regkey change to take effect"
Restart-NetAdapter -Name $ethernetName
Write-Host "Successfully restarted Mellanox network adapter"
Write-Host "For Mellanox CX-3 adapters, if the problem persists please restart the VM"
return;
}
Write-Host "No network device found with '$MellanoxSearchString' in name, exiting."
return;
}
Write-Host "No Network adapter found with '$MellanoxSearchString' in description"
return;
}
Set-NetAdapterPriorityVLanTag