AddBootOptionNoHyperV.ps1 1021 B

1234567891011121314151617181920212223242526272829303132
  1. # AddBootOptionNoHyperV.ps1
  2. # Create a boot option with Hyper-V turned off
  3. # Variables
  4. $description = "Windows 10 Pro -"
  5. # Before doing anything, check if the boot option already exists
  6. $already_added = bcdedit /enum | Select-String "VirtualBox"
  7. If("$already_added" -ne "") {
  8. Write-Host "VirtualBox boot entry already added -- bailing out"
  9. Exit
  10. }
  11. # First, rename the current boot option to "[...] - Hyper V"
  12. bcdedit /set "{current}" description "$description Hyper-V"
  13. # Create a copy of the current boot option
  14. bcdedit /copy "{current}" /d "$description VirtualBox"
  15. # Get the name of the new boot option (assumed to be the last one
  16. # listed by `bcdedit /enum`)
  17. $vboxboot_guid = bcdedit /enum `
  18. | Select-String "description" -Context 3,0 `
  19. | % { $_.Context.PreContext[0] -replace '^identifier +'} `
  20. | Select -Last 1
  21. # Turn off the hypervisor for the new boot entry
  22. bcdedit /set "$vboxboot_guid" hypervisorlaunchtype off
  23. # Make VirtualBox the default boot entry
  24. bcdedit /default "$vboxboot_guid"