-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsl2workaround.ps1
37 lines (32 loc) · 1.02 KB
/
wsl2workaround.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
.SYNOPSIS
Cisco Anyconnect Workaround
.DESCRIPTION
Start or stop the Cisco Anyconnect Workaround
.PARAMETER Action
"start" or "stop"
.PARAMETER File
Optional, path to resolv file
#>
Param(
[String]$Action = "",
[String]$File = "C:\dev\wsl2workaround-resolv.conf"
)
if ( "start" -ilike $Action )
{
Get-NetAdapter | ? {$_.InterfaceDescription -like "*Cisco*" } |Set-NetIPInterface -InterfaceMetric 6000
$dns = (Get-NetIPConfiguration | Where-Object {$_.InterfaceDescription -like "Cisco*"} | Select @{l="IP";e={$_.DNSServer.Serveraddresses}})
Clear-Content -Path $File
foreach($u in $dns.IP){
Add-Content -Path $File -Value "nameserver $u`n" -Encoding "ascii" -NoNewline
}
}
elseif ( "stop" -ilike $Action )
{
Get-NetAdapter | ? {$_.InterfaceDescription -like "*Cisco*" } |Set-NetIPInterface -InterfaceMetric 1
Set-Content -Path $File -Value "nameserver 8.8.8.8`n" -Encoding "ascii" -NoNewline
}
else
{
Get-help $PSCommandPath -Detailed
}