Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command/Powershell script to reset a network adapter

OS: Vista enterprise

When i switch between my home and office network, i always face issues with getting connected to the network. Almost always I have to use the diagnostic service in 'Network and sharing center' and the problem gets solved when i use the reset network adapter option.

This takes a lot of time (3-4 min) and so i was trying to find either a command or a powershell script/cmdlet which i can use directly to reset the network adapter and save myself these 5 mins every time i have to switch between the networks. Any pointers?

like image 738
Mohit Avatar asked Oct 16 '08 03:10

Mohit


People also ask

How do I reset the wireless adapter in PowerShell?

Run the “netsh winsock reset” command Type netsh winsock reset in your PowerShell window when ready and press Enter to run it. It will return a success message and a restart prompt.

What is the command for resetting a network adapter?

Type ipconfig /renew and press Enter. (This will stall for a moment.) Type netsh int ip reset and press Enter.

How do I reset my wireless adapter using CMD?

At the command prompt, run the following commands in the listed order and then check to see if that fixes your connection problem: Type netsh winsock reset and press Enter. Type netsh int ip reset and press Enter. Type ipconfig /release and press Enter.


1 Answers

You can use WMI from within PowerShell to accomplish this. Assuming there is a network adapter who's device name has Wireless in it, the series of commands might look something like the following:

$adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"} $adaptor.Disable() $adaptor.Enable() 

Remember, if you're running this with Window's Vista, you may need to run the PowerShell as Administrator.

like image 136
Scott Saad Avatar answered Sep 23 '22 21:09

Scott Saad