Cisco AnyConnect breaks network connectivity in Ubuntu running under WSL

Despite being primarily a Windows admin, I like to use my WSL Ubuntu instance to access Unixy-networking commands, but establishing AnyConnect VPN sessions breaks network connectivity within the Ubuntu instance. It seems that the fix for this is to open a PowerShell session as administrator and run the following commands:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 4000
Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
It is sometimes also necessary to modify /etc/resolv.conf within Ubuntu to contain the desired resolver entries.
Unfortunately, this has to be done EVERY TIME an AnyConnect VPN session is used concurrently with WSL/Ubuntu.  Apparently, AnyConnect in some manner monkeys around with the HyperV network endpoints and routing in a way that WSL doesn’t like. I hope that they get this fixed SOMEDAY.

Continue reading

Tricking PowerShell Into Treating a String as a Stream

The PowerShell cmdlet Get-FileHash accepts only files or streams as inputs. If I want to generate a hash for a string, I could save it as a file and then feed that file to the command, or I could simply send the string to the command as a string:

PS C:\Working> $stringStream = [System.IO.MemoryStream]::new()
PS C:\Working> $writer = [System.IO.StreamWriter]::new($stringStream)
PS C:\Working> $writer.write("Please hash me.")
PS C:\Working> $writer.Flush()
PS C:\Working> $stringStream.Position = 0
PS C:\Working> Get-FileHash -InputStream $stringStream | Select-Object Hash

Hash
----
50981297AEA627CA3AA5026EB31475FAFD0D28D430165506A2A69B7A30C36AC6