Created
November 23, 2012 19:16
-
-
Save ssilva/3242804686ec2a32abd9 to your computer and use it in GitHub Desktop.
How to disable & enable a network adapter on Windows with PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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