Last active
September 22, 2022 17:11
-
-
Save spddl/cb2708b019582de5615befa3a1489b4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://learn.microsoft.com/en-us/archive/blogs/jhoward/announcing-nvspbind | |
$SettingsFile = "$((Get-Location).Path)\settings.xml" | |
$NetworkAdapter = 'Ethernet' | |
$title = 'Network Settings' | |
### | |
# Get-NetAdapterBinding -IncludeHidden -Name Ethernet -AllBindings | |
$tweakSettings = @("ms_rdma_ndk", "ms_tcpip", "ms_pppoe", "ms_netbt") | |
$l = New-Object System.Management.Automation.Host.ChoiceDescription '&Load', 'Load stored settings' | |
$s = New-Object System.Management.Automation.Host.ChoiceDescription '&Save', 'Save current settings' | |
$t = New-Object System.Management.Automation.Host.ChoiceDescription '&Tweak', 'Tweak Network settings' | |
$options = [System.Management.Automation.Host.ChoiceDescription[]]($l, $s, $t) | |
$defaultOption = 1 | |
if (Test-Path -Path $SettingsFile -PathType Leaf) { | |
$defaultOption = 0 | |
} | |
$result = $host.ui.PromptForChoice($title, '', $options, $defaultOption) | |
switch ($result) { | |
0 { | |
if (-Not (Test-Path -Path $SettingsFile -PathType Leaf)) { | |
Write-Host "settings.xml nicht gefunden" | |
} | |
[XML]$xmlDoc = Get-Content $SettingsFile | |
foreach ($item in $xmlDoc.root.item) { | |
if ($item.enabled) { | |
Set-NetAdapterBinding -Name $NetworkAdapter -ComponentID $item.ComponentID -Enabled $True -IncludeHidden -AllBindings | |
} else { | |
Set-NetAdapterBinding -Name $NetworkAdapter -ComponentID $item.ComponentID -Enabled $False -IncludeHidden -AllBindings | |
} | |
} | |
} | |
1 { | |
[xml]$xmlDoc = New-Object system.Xml.XmlDocument | |
$xmlDoc.LoadXml("<?xml version=`"1.0`" encoding=`"utf-8`"?><root></root>") | |
foreach ($item in Get-NetAdapterBinding -IncludeHidden -Name $NetworkAdapter -AllBindings) { | |
$xmlElt = $xmlDoc.CreateElement("item") | |
$xmlSubElt = $xmlDoc.CreateElement("description") | |
$xmlSubText = $xmlDoc.CreateTextNode($item.Description) | |
[void]$xmlSubElt.AppendChild($xmlSubText) | |
[void]$xmlElt.AppendChild($xmlSubElt) | |
$xmlSubElt = $xmlDoc.CreateElement("enabled") | |
$xmlSubText = $xmlDoc.CreateTextNode($item.Enabled) | |
[void]$xmlSubElt.AppendChild($xmlSubText) | |
[void]$xmlElt.AppendChild($xmlSubElt) | |
$xmlAtt = $xmlDoc.CreateAttribute("componentID") | |
$xmlAtt.Value = $item.ComponentID | |
[void]$xmlElt.Attributes.Append($xmlAtt) | |
[void]$xmlDoc.LastChild.AppendChild($xmlElt) | |
} | |
[void]$xmlDoc.Save($SettingsFile) | |
} | |
2 { | |
foreach ($item in Get-NetAdapterBinding -IncludeHidden -Name $NetworkAdapter -AllBindings) { | |
if ($tweakSettings.Contains($item.ComponentID)) { | |
if (-Not ($item.Enabled)) { | |
Set-NetAdapterBinding -Name $NetworkAdapter -ComponentID $item.ComponentID -Enabled $True -IncludeHidden -AllBindings | |
} | |
} else { | |
if ($item.Enabled) { | |
Set-NetAdapterBinding -Name $NetworkAdapter -ComponentID $item.ComponentID -Enabled $False -IncludeHidden -AllBindings | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment