Created
April 15, 2020 01:06
-
-
Save Albert221/87e2939ada85ea258d2d58ac11f8d9c0 to your computer and use it in GitHub Desktop.
PowerShell script to toggle (enable/disable) Ethernet net adapter
This file contains hidden or 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
# 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