Last active
July 19, 2023 08:16
-
-
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)
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
#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