Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use the version of the distro getting moved #31

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions move-wsl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ function Get-Distros()
# to avoid the unnecessary conversion.
$consoleEncoding = [Console]::OutputEncoding;
[Console]::OutputEncoding = [System.Text.Encoding]::Unicode;
$result = wsl -l -q;
$result = wsl -l -v | ConvertFrom-String -PropertyNames SELECTED, NAME, STATE, VERSION | Select-Object -Skip 1;
[Console]::OutputEncoding = $consoleEncoding;

return $result;
}

# get and make sure there are distros
Write-Host 'Getting distros...';
$distroList = @(Get-Distros);
$distros = @(Get-Distros);
$distroList = $distros | ForEach-Object { $_.NAME };
if ($distroList.Length -le 0)
{
Write-Error 'No distro found';
Expand Down Expand Up @@ -84,11 +85,11 @@ Write-Host "Unregistering WSL ..."

# Importing WSL at new location
Write-Host "Importing $distro from $targetFolder..."
& cmd /c wsl --import $distro $targetFolder "`"$tempFile`"";
# Write-Host 'cmd /c wsl --import $distro "`"$targetFolder`"" "`"$tempFile`"";'
& cmd /c wsl --import $distro $targetFolder "`"$tempFile`"" --version $distros[$selected -1].VERSION;

# Validating
$newDistroList = @(Get-Distros);
$newDistros = @(Get-Distros);
$newDistroList = $newDistros | ForEach-Object { $_.NAME };
if ($newDistroList -notcontains $distro)
{
Write-Error "Import failed. Distro not found. Export file at $tempFile";
Expand Down