Friday, December 2, 2011

“Enable or Disable” Network adapters using Powershell.

 

Hi,

In our IT environment we don’t give  “admin” rights to the normal users and they can’t enable/disable, install/un-install anything.

Today one of our users was having some problem with Wi-FI and to troubleshoot it i need to “enable” and “disable” Wi-Fi network adapter few times, but to enable or disable the network adapter i required to insert the “Administrator” username and password every time {remember my user don’t have admin privileges}.

network_1

This make me mad, i Inserted the username and password approx 10 times {somehow the problem was not resolved and with every change i need to disable and re-enable the wi-fi}, and I also don't want to login as administrator  to the system. Then i thought there must be a PowerShell way to do this and after few minutes of R&D i found the solution of my problem.

Problem:

user don’t have admin privileges to enable/disable any network adapters, so while troubleshooting if you need to enable or disable the network adapter it always ask for Administrator account to do the task.

 

network_1  network_2

Solution :

Run PowerShell as Administrator First

Search for PowerShell and then Right click and choose “Run as administrator

network_3

When PowerShell runs as Administrator, the PS path changed to “C:\widows\System32” and in title bar you can see the “Administrator” is written.

network_4

We will be using  WMI to enable and disable the network adapters.

I do remember that the WMI class for network adapter is start with win32_Network but i forget the full name of the class. lets search it first

  1: Get-WmiObject -List | where  { $_.Name -like "win32_network*"}

in above command we are listing all class in WMI and choosing those to display which starts with Win32_Network


It shows the all classes those are start with Win32_Network , the class which we need is Win32_NetworkAdapter


network_5


ok, lets query the Win32_NetworkAdapter class

  1: Get-WmiObject -Class win32_NetworkAdapter

and you see it shows the list of all network adapter installed in the system.


network_6 


lets filter it more and choose only Name of Adapter to display

  1: Get-WmiObject -Class win32_NetworkAdapter | select name

we piped the command further to Select-Object cmdlet and choose only to display name of the Network adpaters


network_7


Currently I am interested in enable/disable my Wi-Fi network Card. the Name of the  my Wi-Fi network adapter is “Intel(R) Centrino(R) Ultimate-N 6300 AGN


Now I will select only my “Intel(R) Centrino(R) Ultimate-N 6300 AGN” network adapter using where-object cmdlet and in $_.Name i am searching for that Name is Like something “ultimate-n”

  1: get-WmiObject win32_networkadapter |where { $_.name -like "*ultimate-n*"}

Now it showing only one Network Adapter and its showing the network adapter which i want to disable/enable. Our command is working fine till now.


network_8


Now I am going to put the above command in to a variable $wifi.

  1: $wifi = get-WmiObject win32_networkadapter |where { $_.name -like "*ultimate-n*"}

and lets also test the variable too.


All working fine ….


network_9


now pipe the $wifi to get-member cmdlet and check what the methods do we have

  1: $wifi | Get-Member -MemberType Method

NetworkAdapter has 4 methods but we are interested in only 2 for now, the enable and disable method.


To disable a Network adapter we need to use disable()


To enable a Network adapter we need to use enable()


network_10


lets try :)


first Disable it

$wifi.disable()

working


network_11


not enable it

  1: $wifi.enable()

it enabled :)


network_12


Now we can enable/disable network adapters number of times without inserting “Administrator” username and password again and again.


I hope it save someone's time :)


Thanks


Aman Dhally

4 comments:

  1. Solved our problem. Great step by step! Thank you for sharing!

    - Robert

    ReplyDelete
    Replies
    1. You are welcome Robert.
      I glad that this helps you..

      aman

      Delete
  2. I followed this to a T and STILL my gateway t-series wifi won't turn on! I've done everything I can do and what makes me even more upset is this seems to be an ongoing issue ALL OVER the web with very few solutions. I was very excited by this post though and I'm glad it helped some folks, that's awesome! I'm just stumped and am at a complete loss for words!

    ReplyDelete
  3. Is there a way to remotely disable the network adapter using the above commands but without using the enter-pssession command?

    ReplyDelete

Note: Only a member of this blog may post a comment.