Learn about Windows PowerShell
Summary: In Advanced Event 8, you are required to enable and disable network adapters.
About this event
Date of Event
4/11/2012 12:01 AM
4/18/2012 12:01 AM
You are a network consultant. As a result, you travel extensively. Your main computer is your laptop. At times, you may use a wireless network adapter to connect to wireless networks. When you are using wireless, you disable the wired network connection. And at times, you use a wired network connection—when you use a wired network connection you disable the wireless network adapter. You do this to prevent bridging. Currently you use the graphical interface, and it seems to take nearly five minutes to make these changes. You would like to use Windows PowerShell to toggle your network connections. Your task in this scenario is to write a simple Windows PowerShell command to disable all enabled network connections, and enable all disabled network connections. The default output from running the script is sufficient.
2012 Scripting Games: All Links on One Page
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. Good luck as you compete in this year’s Scripting Games. We wish you well.
Ed Wilson, Microsoft Scripting Guy
Ed, what about the possible conditions of (a) No network adapters are enabled, and (b) All network adapters are enabled. Do we need to account for this scenario? Or can we assume that at least one adapter is disabled, and at least one adapter is enabled?
@BigTeddy If all adapters are enabled, that falls in the design point "more than one adapter enabled" IF no adapters are enabled, you should also prompt for which one to enable. Do not assume that you have a 1 enable and 1 disable situation. Make sure that the four design points are hit: each one is a point your script could lose.
Can we assume that we will ignore adapters where IP is not enabled?
I'm not sure if my previous comment made it - I don't see it. Should we have the script ignore the Bluetooth adapter? That would cause a problem in the real world application of this script since most modern laptops have Wireless, Wired, and Bluetooth connections.
@Steve_308 - Took the words right out of my my mouth! Ed (or whomever) strike my Ip enabled question, it was stupid. I second the bluetooth connection question.
Can we assume the laptop is running Vista or newer? Or should we account for older OS's (like XP)?
@Steve_308 @Scott Heath I do not generally ignore the bluetooth adapter ... but I only enable it when I need it (like using a bluetooth mouse or keyboard). What I do is create a filter where I pick up my wireless and my wired connections. So you should not ignore the fact that the bluetooth adapter exists, but I am not wanting to toggle it in this scenario. Your task, in this scenario, is to figure out how to detect a wireless or a wired connection, and how to enable or disable them based upon the rules you decide to implement. So make sure you do not forget about the bluetooth adapter, all the various tunnel adapters, etc. But you will only be working with the wireless and the wired connections in the scenario.
@Ed Withers :-) Vista offered some nice advances in working with network adapters. You should definate check to see if the computer is running Vista or above. A simple OS Version check will suffice. Do not ASSUME that you are running on Vista or above.
If we find that there are more than just 2 adapters (Wireless, Wired, and let's say Bluetooth), is it acceptable to prompt for which to enable/disable and include Bluetooth in that prompt or do you want Bluetooth filtered out entirely so it's not even an option?
@jeremy Caauwe yes, if there are more than two adapters it is acceptible to prompt for which one to enable / disable.