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


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.