Enable/Disable Wi-Fi Adapter based on Wired adapter status

There are plenty of articles around the Internet discussing how to enable or disable a Wi-Fi adapter based on the status of the wired connection. Whilst I’ve seen that some Dell laptops have this as a simple option in BIOS, our Lenovo machines do not, so this post describes how I achieved a workable solution.

Most modern NIC drivers log an event to the System log when a link is established or disconnected:

2015-07-07 13_59_29

This means that it’s possible to create a scheduled task with triggers to look for those specific events, and run a script to enable or disable the wireless adapter.

Some people set up multiple tasks, and multiple scripts, to enable/disable the adapter, but I found it easier to create a single script that runs whenever any of these events occur:

  1. e1dexpress and e1cexpress – Event ID 32 (Link established)
  2. e1dexpress and e1cexpress – Event ID 27 (Link disconnected)
  3. On workstation unlock (useful if the computer is put to sleep, and then un-docked)
  4. At system startup

Note that the script may not work out-of-the-box if you don’t have a NIC that’s driven by one of the above drivers.

I currently push the script and the scheduled task configuration out using Group Policy Preferences.

#Requires -Version 4.0 -RunAsAdministrator
Manage-WiFiStatus.ps1 – Enable/Disable WiFi based on wired connectivity status
Disables the Wi-Fi adapter if the wired one is connected, and vice versa.
This is built for internal use on Windows 8.1, and depends on the new *-NetAdapter cmdlets in PS 4.0
The point of this script is to run it based on System Event Log events that the NIC drivers
create when the physical NIC is plugged in or unplugged. Alternatively, you could just schedule it
to run periodically.
Written By: Daniel Streefkerk
Website: http://daniel.streefkerkonline.com
Twitter: http://twitter.com/dstreefkerk
Change Log
v1.0, 06/03/2014 – Initial version
v1.1, 07/07/2015 – Replaced Write-Host with Write-Verbose
# Get the NICs. This depends on them being named according to Windows 8's defaults
$wiredNic = Get-NetAdapter "ethernet" ErrorAction SilentlyContinue WarningAction SilentlyContinue
$wirelessNic = Get-NetAdapter "wi-fi" ErrorAction SilentlyContinue WarningAction SilentlyContinue
# If we can't figure out the NICs, bail out
If (($wiredNic -eq $null) -or ($wirelessNic -eq $null)) {
Write-Verbose "Couldn't find network adapters. Perhaps they're not named 'Ethernet' and 'Wi-Fi'?"
Write-Verbose "Wired NIC: $($wiredNic.InterfaceDescription)"
Write-Verbose "Wireless NIC: $($wirelessNic.InterfaceDescription)"
switch ($wiredNic.MediaConnectionState) {
"Connected" {
Write-Verbose "Physical NIC is connected. Disabling Wi-Fi Adapter"
$wirelessNic | Disable-NetAdapter Confirm:$false
"Disconnected" {
Write-Verbose "Physical NIC is disconnected. Enabling Wi-Fi Adapter"
$wirelessNic | Enable-NetAdapter Confirm:$false

Note that this script depends on the network adapters having their default names as per Windows 8.x’s naming. Also, PowerShell 4.0 is required, as the script makes use of the newer *-NetAdapter cmdlets.

2 thoughts on “Enable/Disable Wi-Fi Adapter based on Wired adapter status

  1. Hi ,

    How do i identify event id for cellular in windows 10 if it goes down or up ? and is there any ways to switch to WIFI whenever my Cellular goes down ?


    • Hi,

      It really depends on the hardware and drivers in use. Perhaps the cellular adapter doesn’t log any information. Or, you may need to enable a specific event log that’s disabled by default.

      Sorry if that’s not much help…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s