Skip to content

Instantly share code, notes, and snippets.

@ssilva
Created November 23, 2012 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssilva/3242804686ec2a32abd9 to your computer and use it in GitHub Desktop.
Save ssilva/3242804686ec2a32abd9 to your computer and use it in GitHub Desktop.
How to disable & enable a network adapter on Windows with PowerShell
# Get the network adapter object
$adapter = Get-WmiObject -Class Win32_NetworkAdapter |
Where-Object {$_.Name -eq "TP-LINK Wireless USB Adapter"}
# Disable it
Write-Host -nonew "Disabling $($adapter.Name)... ";
$result = $adapter.Disable()
if ($result.ReturnValue -eq -0) {
Write-Host "Success.";
} else {
Write-Host "Failed.";
}
# Wait 2 seconds
Start-Sleep -s 2
# Enable it
Write-Host -nonew "Enabling $($adapter.Name)... ";
$result = $adapter.Enable()
if ($result.ReturnValue -eq -0) {
Write-Host "Success.";
} else {
Write-Host "Failed.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment