Skip to content

Instantly share code, notes, and snippets.

@Albert221
Created April 15, 2020 01:06
Show Gist options
  • Save Albert221/87e2939ada85ea258d2d58ac11f8d9c0 to your computer and use it in GitHub Desktop.
Save Albert221/87e2939ada85ea258d2d58ac11f8d9c0 to your computer and use it in GitHub Desktop.
PowerShell script to toggle (enable/disable) Ethernet net adapter
# Run as administrator - https://stackoverflow.com/a/57035712/3158312
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
exit;
}
$adapterName = 'Ethernet'
$status = Get-NetAdapter -Name $adapterName | Format-List -Property "Status" | Out-String
if ($status -Match 'Up') {
Disable-NetAdapter -Name $adapterName -Confirm:$false
} else {
Enable-NetAdapter -Name $adapterName -Confirm:$false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment