I’m running wsl -l -v
to get a list of WSL VMs on my computer and I get a list like this:
NAME STATE VERSION
Ubuntu-18-04 Stopped 2
Ubuntu-20-04 Running 2
I only want to see the ones that are running.
I tried:
wsl -l -v | Select-Object NAME
but I just get a list of blank lines.
2
Answers
just found this in –help docs
output:
While your specific use-case can be handled by
wsl --list --running
(as mentioned by @X--FARZA_D--X’s answer), there are two reasons why your filter wasn’t working:First, you probably were looking for
Select-String Running
. PowerShell’sSelect-Object
would require a PowerShell object with aNAME
property. Allwsl.exe
provides is a string output.But more importantly, it still won’t work even after the proper:
This is due to a bug in
wsl.exe
that causes it output as a mangled UTF-16. See this and this answer for details.Given your use-case, you should be able to properly filter with:
Alternatively, if you are using a recent release of WSL (0.64.0 or later) on Windows 11, you could simply: