Browse Source

add bcdedit

liuyuqi-dellpc 5 years ago
parent
commit
e5997d65e2
1 changed files with 32 additions and 0 deletions
  1. 32 0
      AddBootOptionNoHyperV.ps1

+ 32 - 0
AddBootOptionNoHyperV.ps1

@@ -0,0 +1,32 @@
+# AddBootOptionNoHyperV.ps1
+# Create a boot option with Hyper-V turned off
+
+# Variables
+$description = "Windows 10 Pro -"
+
+# Before doing anything, check if the boot option already exists
+$already_added = bcdedit /enum | Select-String "VirtualBox"
+
+If("$already_added" -ne "") {
+    Write-Host "VirtualBox boot entry already added -- bailing out"
+    Exit
+}
+
+# First, rename the current boot option to "[...] - Hyper V"
+bcdedit /set "{current}" description "$description Hyper-V"
+
+# Create a copy of the current boot option
+bcdedit /copy "{current}" /d "$description VirtualBox"
+
+# Get the name of the new boot option (assumed to be the last one
+# listed by `bcdedit /enum`)
+$vboxboot_guid = bcdedit /enum `
+    | Select-String "description" -Context 3,0 `
+    | % { $_.Context.PreContext[0] -replace '^identifier +'} `
+    | Select -Last 1
+
+# Turn off the hypervisor for the new boot entry
+bcdedit /set "$vboxboot_guid" hypervisorlaunchtype off
+
+# Make VirtualBox the default boot entry
+bcdedit /default "$vboxboot_guid"