I am attempting to use PowerShell to grab useful output from wsl.exe. For the life of me, I cannot seem to match for strings in the output (see below). I get the same behavior in both PowerShell 5 and 7. Does anyone have a reliable means to capture the output of wsl.exe?
Thanks
PS C:\Users\gsamuel> $foo = (wsl -l -v)
PS C:\Users\gsamuel> $foo
NAME STATE VERSION
* Ubuntu-20.04 Running 2
PS C:\Users\gsamuel> $foo | Select-String -Pattern 'Ubuntu'
PS C:\Users\gsamuel> $foo -match 'Ubuntu'
PS C:\Users\gsamuel>
PS C:\Users\gsamuel>
PS C:\Users\gsamuel> [string]$foo | Select-String -Pattern 'Ubuntu'
PS C:\Users\gsamuel> [string]$foo -match 'Ubuntu'
False