Skip to content

Instantly share code, notes, and snippets.

@pduchnovsky
Last active December 11, 2023 11:40
Show Gist options
  • Save pduchnovsky/c4bc56197c64a4ad095a8dc74d1908f4 to your computer and use it in GitHub Desktop.
Save pduchnovsky/c4bc56197c64a4ad095a8dc74d1908f4 to your computer and use it in GitHub Desktop.
# Restart Adapter when not UP (intel i225-v and i226-v issue workaround)
# Script developed by pduchnovsky
# https://duchnovsky.com/2023/02/automated-adapter-restart/
$AdapterName = "Ethernet"
$PowerShellPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Argument = "-command `"Get-NetAdapter $AdapterName | ? status -ne up | Restart-NetAdapter`""
$Name = "Restart Adapter"
$Trigger = New-ScheduledTaskTrigger -AtStartup
$Action = New-ScheduledTaskAction -Execute $PowerShellPath $Argument
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -ExecutionTimeLimit 0
$Principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName $Name -Trigger $Trigger -Action $Action -Settings $Settings -Principal $Principal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment