Disable WiFi with PowerShell

A bit like putting your laptop into Flight Mode, I guess.

I fly fairly often at the moment, but my Wireless switch on the side of my laptop is slowly wearing out. Occasionally when it's in the OFF position, it thinks it's actually in the ON position for a moment, and I see the WiFi LED come on. It's probably a warranty item which I should get fixed soon. But until I do, I'm in the habit of opening up Computer Manager and disabling the device.

So I got to thinking that I should be able to do this with PowerShell, and make myself a "FlightMode" script.

I started by figuring that there must be a WMI class that described the network adapters. So I ran:

get-wmiobject -list | select-string adapter

Sure enough, one of them was Win32_NetworkAdapter. So now I could identify the network adapters available.

get-wmiobject -class win32_networkadapter -namespace root\CIMV2

Great. Plenty of them, but in particular, one that was my Wireless one. I could grab that alone by running:

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wireless"}

Now to find out out how to disable or enable it. Easy… pipe my object into get-member.

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wireless"} | get-member

Seeing Enable() and Disable() methods makes this easy…

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wireless"} | % {$_.Disable()}

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wireless"} | % {$_.Enable()}

I'm looking for anything that matches "Wireless", just in case. I really don't want to be on a plane and accidentally using a WiFi network adapter. Next I need to work out a script which will switch my timezone.

2 thoughts on “Disable WiFi with PowerShell”

Leave a Reply

Your email address will not be published. Required fields are marked *