skip to Main Content

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


  1. just found this in –help docs

    wsl -l --running
    

    output:

    Windows Subsystem for Linux Distributions:
    Ubuntu (Default)
    
    Login or Signup to reply.
  2. 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’s Select-Object would require a PowerShell object with a NAME property. All wsl.exe provides is a string output.

    But more importantly, it still won’t work even after the proper:

    wsl -l -v | Select-String Running
    

    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:

    $console = ([console]::OutputEncoding)
    [console]::OutputEncoding = New-Object System.Text.UnicodeEncoding
    wsl -l -v | Select-String Running
    [console]::OutputEncoding = $console
    

    Alternatively, if you are using a recent release of WSL (0.64.0 or later) on Windows 11, you could simply:

    $env:WSL_UTF8=1
    wsl -l -v | Select-String Running
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search