Skip to content

Instantly share code, notes, and snippets.

@A-725-K
Last active July 19, 2023 08:16
Show Gist options
  • Save A-725-K/5d9042fdfd6161b61fbac37a03729fd8 to your computer and use it in GitHub Desktop.
Save A-725-K/5d9042fdfd6161b61fbac37a03729fd8 to your computer and use it in GitHub Desktop.
Utility to switch between WSL and Virtual Machines (it requires admin privileges)
#Requires -RunAsAdministrator
# getting the Hypervisor Launch type
$hypervType = $null;
(bcdedit /enum '{current}' | ForEach-Object -process {
$tmp = $($_.split(' ') | Sort-Object | Get-Unique);
If ($tmp.Count -eq 3 -And $tmp[1] -eq 'hypervisorlaunchtype') {
$hypervType = $($tmp[2]);
}
}
);
Write-Output "HYPERV-TYPE ===> $hypervType"
If ($hypervType -eq 'Auto') {
Write-Output "Switching to 'off'... ---> You can use VMWare/VirtualBox"
bcdedit /set '{current}' hypervisorlaunchtype off
} Else {
Write-Output "Switching to 'auto'... ---> You can use WSL"
bcdedit /set '{current}' hypervisorlaunchtype auto
}
$answer = Read-Host -Prompt 'Would you like to restart your PC now ? [yes/no]'
If ($answer -eq 'yes') {
Write-Output 'Restarting....'
Restart-Computer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment