Enable/Disable Network Connection
Whilst waiting for lunch, i stumbled across this post on Channel9, https://channel9.msdn.com/ShowPost.aspx?PostID=158556. It is c# code for enabling and disabling network adapters. I thought you must be able to do this with PowerShell easier.
In Vista there is a win32_NetworkAdapter wmi provider - whoop. Problem solved.
PS C:\> Get-wmiobject win32_NetworkAdapter | format-table
will get you a list of adapters installed on your machine. My wireless adapter was deviceId 5, so this line gets me the device
PS C:\> Get-WmiObject win32_networkadapter | where {$_.DeviceId -eq 5}
ServiceName : NETw2v32
MACAddress : 00:13:CE:8A:4B:C5
AdapterType : Ethernet 802.3
DeviceID : 5
Name : Intel(R) PRO/Wireless 2915ABG Network Connection
NetworkAddresses :
Speed : 11000000
Saving this to a variable to work with is easy
$wireless = Get-WmiObject win32_networkadapter | where {$_.DeviceId -eq 5}
Now i can interact with my wireless adapter and do such things as
$wireless.Disable()
$wireless.Enable()
Cool - add the variable to your profile and everytime you open up powershell you can interact with your network adapter, no C# console. No VBS to run. Nice clean and simple.
Comments
Anonymous
March 14, 2007
Hi Devid i want to disable ethernet and internet on a work station through VC++.So can you help me out urgenly. some code would be appreciable Thansk in advance RYKAnonymous
April 27, 2007
The comment has been removedAnonymous
April 27, 2007
I've just looked on my XP machine and it appears that Disable is not supported on XP. It must be new to Windows Vista.