diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 319100b9..5eddae00 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -9681,10 +9681,14 @@ function Install-WSL { [System.Console]::OutputEncoding = [System.Text.Encoding]::Unicode - $Distros = (wsl --list --online | Select-Object -Skip 4).Replace(" ", "").Replace("* ", "") | ForEach-Object -Process { + $wsl = wsl --list --online + # We need to get the string number where the "FRIENDLY NAME" header begins to truncate all other unnecessary strings in the beginning + $LineNumber = ($wsl | Select-String -Pattern "FRIENDLY NAME" -CaseSensitive).LineNumber + # Remove first strings in output from the first to the $LineNumber + $Distros = ($wsl).Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { [PSCustomObject]@{ - "Distro" = $_ -split " ", 2 | Select-Object -Last 1 - "Alias" = $_ -split " ", 2 | Select-Object -First 1 + "Distro" = ($_ -split " ", 2 | Select-Object -Last 1).Trim() + "Alias" = ($_ -split " ", 2 | Select-Object -First 1).Trim() } } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 4940dbce..6a30f558 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -8649,10 +8649,14 @@ function Install-WSL { [System.Console]::OutputEncoding = [System.Text.Encoding]::Unicode - $Distros = (wsl --list --online | Select-Object -Skip 4).Replace(" ", "").Replace("* ", "") | ForEach-Object -Process { + $wsl = wsl --list --online + # We need to get the string number where the "FRIENDLY NAME" header begins to truncate all other unnecessary strings in the beginning + $LineNumber = ($wsl | Select-String -Pattern "FRIENDLY NAME" -CaseSensitive).LineNumber + # Remove first strings in output from the first to the $LineNumber + $Distros = ($wsl).Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { [PSCustomObject]@{ - "Distro" = $_ -split " ", 2 | Select-Object -Last 1 - "Alias" = $_ -split " ", 2 | Select-Object -First 1 + "Distro" = ($_ -split " ", 2 | Select-Object -Last 1).Trim() + "Alias" = ($_ -split " ", 2 | Select-Object -First 1).Trim() } } diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 4bc3088b..f24d0b11 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -9684,10 +9684,14 @@ function Install-WSL { [System.Console]::OutputEncoding = [System.Text.Encoding]::Unicode - $Distros = (wsl --list --online | Select-Object -Skip 4).Replace(" ", "").Replace("* ", "") | ForEach-Object -Process { + $wsl = wsl --list --online + # We need to get the string number where the "FRIENDLY NAME" header begins to truncate all other unnecessary strings in the beginning + $LineNumber = ($wsl | Select-String -Pattern "FRIENDLY NAME" -CaseSensitive).LineNumber + # Remove first strings in output from the first to the $LineNumber + $Distros = ($wsl).Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { [PSCustomObject]@{ - "Distro" = $_ -split " ", 2 | Select-Object -Last 1 - "Alias" = $_ -split " ", 2 | Select-Object -First 1 + "Distro" = ($_ -split " ", 2 | Select-Object -Last 1).Trim() + "Alias" = ($_ -split " ", 2 | Select-Object -First 1).Trim() } } diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index f9017053..51fb622b 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -9346,10 +9346,10 @@ function Install-WSL # We need to get the string number where the "FRIENDLY NAME" header begins to truncate all other unnecessary strings in the beginning $LineNumber = ($wsl | Select-String -Pattern "FRIENDLY NAME" -CaseSensitive).LineNumber # Remove first strings in output from the first to the $LineNumber - $Distros = ($wsl).Replace(" ", "").Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { + $Distros = ($wsl).Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { [PSCustomObject]@{ - "Distro" = $_ -split " ", 2 | Select-Object -Last 1 - "Alias" = $_ -split " ", 2 | Select-Object -First 1 + "Distro" = ($_ -split " ", 2 | Select-Object -Last 1).Trim() + "Alias" = ($_ -split " ", 2 | Select-Object -First 1).Trim() } } diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 8cf3bf31..ac9cbaad 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -9349,10 +9349,10 @@ function Install-WSL # We need to get the string number where the "FRIENDLY NAME" header begins to truncate all other unnecessary strings in the beginning $LineNumber = ($wsl | Select-String -Pattern "FRIENDLY NAME" -CaseSensitive).LineNumber # Remove first strings in output from the first to the $LineNumber - $Distros = ($wsl).Replace(" ", "").Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { + $Distros = ($wsl).Replace("* ", "")[($LineNumber)..(($wsl).Count)] | ForEach-Object -Process { [PSCustomObject]@{ - "Distro" = $_ -split " ", 2 | Select-Object -Last 1 - "Alias" = $_ -split " ", 2 | Select-Object -First 1 + "Distro" = ($_ -split " ", 2 | Select-Object -Last 1).Trim() + "Alias" = ($_ -split " ", 2 | Select-Object -First 1).Trim() } }