Created
December 6, 2021 06:30
-
-
Save csghone/2aaeca0fbe750c0e56f1b6221e55b30e to your computer and use it in GitHub Desktop.
Powershell script to setup DNS for WSL on a Cisco VPN
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
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process | |
Write-Host > c:\tools\local_ip.txt | |
# Capture Wi-FI IP address | |
#Get-NetIPConfiguration | Where-Object {$_.InterfaceDescription -Match "Wi-Fi 6 AX201 160MHz"} | Where-Object {$_.NetAdapter.Status -NotMatch "Disconnected"} | Select-Object IPv4Address >> c:\tools\local_ip.txt | |
#Get-NetIPConfiguration | Where-Object {$_.InterfaceDescription -Match "I219-LM"} | Where-Object {$_.NetAdapter.Status -NotMatch "Disconnected"} | Select-Object IPv4Address >> c:\tools\local_ip.txt | |
Get-NetIPConfiguration | Where-Object {$_.NetAdapter.Status -NotMatch "Disconnected"} | Where-Object {$_.InterfaceDescription -NotMatch "Cisco AnyConnect"} | Where-Object {$_.InterfaceDescription -NotMatch "Virtual Ethernet"} |Select-Object IPv4Address >> c:\tools\local_ip.txt | |
# Get DNS servers | |
Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses > c:\tools\dns_servers.txt | |
# Change metric to ensure WSL traffic gets routed correctly | |
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Where-Object {$_.Status -NotMatch "Disabled"} | Set-NetIPInterface -InterfaceMetric 6000 | |
# Capture VPN IP address | |
Get-NetIPConfiguration | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Select-Object IPv4Address > c:\tools\vpn_ip.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment