I want my powershell script to detect which WSL distribution is installed
PS> wsl -l
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
PS> wsl -l | where {$_ -match "^Ubuntu"}
# Doesn't print anything
I would expect it to print:
Ubuntu (Default)
A few more experiments:
PS> $x = wsl -l
PS> $x.GetType()
True True Object[] System.Array
PS> $x[0].GetType()
True True String System.Object
PS> $x[1].GetType()
True True String System.Object
[Console]::OutputEncoding, which on Windows defaults to the given system's legacy OEM code page (e.g.437on US-English systems) If a given external program uses a different encoding,[Console]::OutputEncodingmust (temporarily) be set to that encoding. See this answer for more information and helper functions.wsl -loutputs UTF-16LE ("Unicode") encoded text, as explained in the linked duplicate.