Disabling Network Adapters

by Nov 29, 2010

If you need to systematically disable network adapters, all you need is the name of the adapter (as stated in your control panel or returned by Get-NetworkAdapter, a function featured in another tip). Of course, you will also need Administrator privileges. Here is the function to disable network adapters:

function Disable-NetworkAdapter {
param(
$name
)
Get-WmiObject Win32_NetworkAdapter Filter "NetConnectionID='$name'" |
ForEach-Object {
$rv = $_.Disable().ReturnValue
if ($rv -eq 0) {
'{0} disabled' -f $_.Caption
} else {
'{0} could not be disabled. Error code {1}' -f $_.Caption, $rv
}
}
}

Twitter This Tip!
ReTweet this Tip!