I need to find my wsl kernel version in a script, so I'm trying to run wsl --status
to find it out, but when I try to -match
it, PowerShell won't find what I'm looking for:
$wsl = wsl --status
(Invoke-Command { wsl --status | Out-String }) -match 'kernel'
False
I was able to find a workaround using IndexOf
:
$wsl = wsl --status
(Invoke-Command { wsl --status | Out-String }).IndexOf('kernel')
412
That workaround definitely solves my problem, but I'd like to understand what's going on, because it makes no sense to me.
Maybe it's a character encoding issue, I don't know... So far, I tried changing [Console]::OutputEncoding
and using [System.Text.Encoding]::Convert
, [System.Text.Encoding]::UTF8.GetString
and [System.Text.Encoding]::UTF8.GetBytes
with no success.
Thanks in advance!