I want to run a powershell script which will run the wsl --status
command, capture the stdout output into a variable and then use Regex
to return the name of the default distribution.
Problem is, the stdout output contains what appears to be nulls or spaces between each character.
How to capture stdout into a variable where the text is something I can run a regex against?
$cmdOutput = &wsl --status | Out-String
Write-Output $cmdOutput
$pattern = "Default Distribution:\s+([\d\w-_\.]+)"
$results = [Regex]::Matches($cmdOutput, $pattern)
if ($results.count -gt 0 )
{
$item = $results[0]
Write-Output $item.Groups[1].Value
}