Created
September 6, 2020 08:07
-
-
Save karthiks/82a6a6e2f2fb4ff69ce91ceb3f62a086 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to change the default user | |
Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); }; | |
# Usage | |
# WSL-SetDefaultUser <DistroName> <UserName> | |
$title = 'WSL Import' | |
$question = 'The current Ubuntu WSL system will be unregistered, and the new VHD imported. Are you sure you want to proceed?' | |
$choices = '&Yes', '&No' | |
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1) | |
if ($decision -eq 0) { | |
Write-Host 'Continuing with deregistration of Ubuntu, and import of replacement VHD' | |
wsl --unregister Ubuntu | |
Write-Host 'Importing VHD...' | |
wsl --import Ubuntu D:\VMs\WSL\Ubuntu\ D:\Temp\ubuntu.tar --version 2 | |
Write-Host 'Setting default user...' | |
WSL-SetDefaultUser Ubuntu tony | |
} else { | |
Write-Host 'Operation canceled.' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment