Sometimes, it is necessary to reset network adapters, such as after you changed settings for that adapter in your registry. Resetting a network adapter is done by first disabling and then enabling it again. Here are three functions you can use:
function Disable-NetworkAdapter {
param(
$name
)
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
}
}
}
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
}
}
}
function Enable-NetworkAdapter {
param(
$name
)
param(
$name
)
Get-WmiObject Win32_NetworkAdapter –Filter "NetConnectionID='$name'" |
ForEach-Object {
$rv = $_.Enable().ReturnValue
if ($rv -eq 0) {
'{0} enabled' -f $_.Caption
} else {
'{0} could not be enabled. Error code {1}' -f $_.Caption, $rv
}
}
}
ForEach-Object {
$rv = $_.Enable().ReturnValue
if ($rv -eq 0) {
'{0} enabled' -f $_.Caption
} else {
'{0} could not be enabled. Error code {1}' -f $_.Caption, $rv
}
}
}
function Restart-NetworkAdapter {
param(
$name
)
param(
$name
)
Disable-NetworkAdapter $name
Enable-NetworkAdapter $name
Enable-NetworkAdapter $name
}
Try this to reset a network adapter:
Restart-NetworkAdapter LAN-Connection
A restart will require Administrator privileges. Otherwise, you will receive error code 5 (Access Denied).