Last active
June 13, 2024 12:12
-
-
Save Shterneregen/a512496243d2d996a50f63f6b2b6de7d to your computer and use it in GitHub Desktop.
Revisions
-
Shterneregen revised this gist
Jun 28, 2023 . 2 changed files with 19 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,10 @@ # - Create CreateScheduledTask.ps1 file with content below. # - Run as admin command in PowerShell: # Get-Content .\CreateScheduledTask.ps1 | PowerShell.exe -noprofile - # - Restart Windows # - Launch WSL # - Launch VPN # - Done! Metric automatically updated $taskname="Fix VPN for WSL" $scriptName = "UpdateAnyConnectInterfaceMetric.ps1" 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ # Task to start WSL on Windows logon # Run as admin command in PowerShell: # Get-Content .\wsl-on-logon.ps1 | PowerShell.exe -noprofile - $taskname="Start WSL on logon" $trigger= New-ScheduledTaskTrigger -AtLogon $triggers = @() $triggers += $trigger $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0 $user = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName $action = New-ScheduledTaskAction -Execute "wsl" Register-ScheduledTask -TaskName $taskname -Trigger $triggers -User $user -Action $action -Settings $settings -RunLevel Highest -Force -
Shterneregen revised this gist
Jun 4, 2023 . No changes.There are no files selected for viewing
-
Shterneregen revised this gist
Jun 4, 2023 . 1 changed file with 16 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,30 +3,33 @@ # And run as admin command in PowerShell: # Get-Content .\CreateScheduledTask.ps1 | PowerShell.exe -noprofile - $taskname="Fix VPN for WSL" $scriptName = "UpdateAnyConnectInterfaceMetric.ps1" $commandToUpdateMetric = "Get-NetAdapter | Where-Object {`$_.InterfaceDescription -Match 'Cisco AnyConnect'} | Set-NetIPInterface -InterfaceMetric 5500" $profilePath = $env:USERPROFILE $scriptPath = "$profilePath\$scriptName" if(Test-Path -Path $scriptPath){ Write-Output "File '$scriptPath' already exists" } else { New-Item -ItemType File -Path $scriptPath -Value $commandToUpdateMetric Write-Output "File '$scriptPath' created successfully" } $triggerClass = Get-CimClass -ClassName MSFT_TaskEventTrigger -Namespace Root/Microsoft/Windows/TaskScheduler:MSFT_TaskEventTrigger $trigger = New-CimInstance -CimClass $triggerClass -ClientOnly $trigger.Subscription = @" <QueryList><Query Id="0" Path="Cisco AnyConnect Secure Mobility Client"><Select Path="Cisco AnyConnect Secure Mobility Client">*[System[Provider[@Name='acvpnagent'] and EventID=2039]]</Select></Query></QueryList> "@ $trigger.Enabled = $True $triggers = @() $triggers += $trigger $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0 $user = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName $action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-Command Get-Content '$scriptPath' | PowerShell.exe -noprofile -" Register-ScheduledTask -TaskName $taskname -Trigger $triggers -User $user -Action $action -Settings $settings -RunLevel Highest -Force -
Shterneregen revised this gist
Jun 1, 2023 . No changes.There are no files selected for viewing
-
Shterneregen created this gist
Jun 1, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ # Create CreateScheduledTask.ps1 file with content below. # And run as admin command in PowerShell: # Get-Content .\CreateScheduledTask.ps1 | PowerShell.exe -noprofile - $profilePath = $env:USERPROFILE $scriptName = "UpdateAnyConnectInterfaceMetric.ps1" $scriptPath = "$profilePath\$scriptName" if(!(Test-Path -Path $scriptPath)){ New-Item -ItemType File -Path $scriptPath -Value "Get-NetAdapter | Where-Object {`$_.InterfaceDescription -Match 'Cisco AnyConnect'} | Set-NetIPInterface -InterfaceMetric 5500" Write-Output "File '$scriptPath' created successfully" } else { Write-Output "File '$scriptPath' already exists" } $taskname="Fix VPN for WSL" $triggers = @() $CIMTriggerClass = Get-CimClass -ClassName MSFT_TaskEventTrigger -Namespace Root/Microsoft/Windows/TaskScheduler:MSFT_TaskEventTrigger $trigger = New-CimInstance -CimClass $CIMTriggerClass -ClientOnly $trigger.Subscription = @" <QueryList><Query Id="0" Path="Cisco AnyConnect Secure Mobility Client"><Select Path="Cisco AnyConnect Secure Mobility Client">*[System[Provider[@Name='acvpnagent'] and EventID=2039]]</Select></Query></QueryList> "@ $trigger.Enabled = $True $triggers += $trigger $User = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName $Action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "-Command Get-Content '$scriptPath' | PowerShell.exe -noprofile -" Register-ScheduledTask -TaskName $taskname -Trigger $triggers -User $User -Action $Action -RunLevel Highest -Force